Skip to content

Commit 618289d

Browse files
tomwhitejeromekelleher
authored andcommitted
Treat ValueError as known user errors
1 parent 2e01a9d commit 618289d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

tests/test_bcftools_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,4 @@ def test_error(tmp_path, args, vcf_name):
175175
assert bcftools_error.startswith("Error:") or bcftools_error.startswith("[E::")
176176

177177
_, vcztools_error = run_vcztools(f"{args} {vcz_path}", expect_error=True)
178-
assert vcztools_error.startswith("Error:")
178+
assert "Error:" in vcztools_error

vcztools/cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ def handle_broken_pipe(output):
3131

3232
def handle_exception(func):
3333
"""
34-
Handle application exceptions by converting to a ClickException,
35-
so the message is written to stderr and a non-zero exit code is set.
34+
Handle known application exceptions (ValueError) by converting to
35+
a ClickException, so the message is written to stderr and a non-zero exit
36+
code is set.
3637
"""
3738

3839
@wraps(func)
3940
def wrapper(*args, **kwargs):
4041
try:
4142
return func(*args, **kwargs)
42-
except Exception as e:
43+
except ValueError as e:
4344
raise click.ClickException(e) from e
4445

4546
return wrapper
@@ -222,7 +223,8 @@ def view(
222223
)
223224

224225
if samples_file:
225-
assert not samples, "vcztools does not support combining -s and -S"
226+
if samples is not None:
227+
raise ValueError("vcztools does not support combining -s and -S")
226228

227229
samples = ""
228230
exclude_samples_file = samples_file.startswith("^")

0 commit comments

Comments
 (0)