Skip to content

Commit

Permalink
Treat ValueError as known user errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite authored and jeromekelleher committed Feb 20, 2025
1 parent 2e01a9d commit 618289d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/test_bcftools_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ def test_error(tmp_path, args, vcf_name):
assert bcftools_error.startswith("Error:") or bcftools_error.startswith("[E::")

_, vcztools_error = run_vcztools(f"{args} {vcz_path}", expect_error=True)
assert vcztools_error.startswith("Error:")
assert "Error:" in vcztools_error
10 changes: 6 additions & 4 deletions vcztools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ def handle_broken_pipe(output):

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

@wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
except ValueError as e:
raise click.ClickException(e) from e

return wrapper
Expand Down Expand Up @@ -222,7 +223,8 @@ def view(
)

if samples_file:
assert not samples, "vcztools does not support combining -s and -S"
if samples is not None:
raise ValueError("vcztools does not support combining -s and -S")

samples = ""
exclude_samples_file = samples_file.startswith("^")
Expand Down

0 comments on commit 618289d

Please sign in to comment.