Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print error messages not stacktraces #140

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

tomwhite
Copy link
Contributor

@tomwhite tomwhite commented Feb 19, 2025

Fixes #137

I haven't tried to harmonise the error messages or exit codes (#117) here - just looking for a string "Error:" and a non-zero exit code.

Add bcftools validation tests for error conditions.
Copy link
Contributor

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great approach, but I think it's too broad at the moment and will prevent bugs from getting reported. I don't want to close #139 until we stop abusing assert for UI purposes.

Ideally we'd have our own exception class hierarchy which would let us precisely state which exceptions we think are things that should get reported to the user as an input error, but that's a lot of work.

vcztools/cli.py Outdated
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good approach, but I think we should stack trace when unexpected exceptions happen. Perhaps we could catch ValueErrors here instead, which would probably get most of the actual interface errors we expect?

In particular, we should check to see if it's already a ClickException and just reraise if so. Otherwise we're losing a bunch of subtlety.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - nice usage of functools.wraps!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good approach, but I think we should stack trace when unexpected exceptions happen. Perhaps we could catch ValueErrors here instead, which would probably get most of the actual interface errors we expect?

Done.

@tomwhite
Copy link
Contributor Author

Great approach, but I think it's too broad at the moment and will prevent bugs from getting reported. I don't want to close #139 until we stop abusing assert for UI purposes.

I totally agree. I had a quick look at where we have assert in the code and most of them are for checking invariants - i.e. not things that a user could violate by specifying something on the command line. But we should keep #139 open for deciding what to do with these.

There was one assert with a message that was being abused for checking incorrect user input (message "vcztools does not support combining -s and -S") that I have now changed to a ValueError.

Copy link
Contributor

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jeromekelleher
Copy link
Contributor

Created #141 to track dealing with IO errors, which should be straightforward.

@jeromekelleher jeromekelleher merged commit 618289d into sgkit-dev:main Feb 20, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add bcftools validation tests for error conditions
2 participants