-
Notifications
You must be signed in to change notification settings - Fork 228
Add new exception GMTValueError for invalid values #3985
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
base: main
Are you sure you want to change the base?
Conversation
ddf56de
to
efa6715
Compare
340b235
to
8472d86
Compare
8472d86
to
a590758
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking if this should be marked as a breaking change, because the exception type changes from GMTInvalidInput
to GMTValueError
, and code like try: ... except GMTInvalidInput: ...
would break. But unsure if users even have code like that which matches on GMTInvalidInput.
Other than that, some minor suggestions/questions below.
@@ -51,3 +54,57 @@ class GMTImageComparisonFailure(AssertionError): # noqa: N818 | |||
""" | |||
Raised when a comparison between two images fails. | |||
""" | |||
|
|||
|
|||
class GMTValueError(GMTError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be subclassed from both GMTError
and ValueError
?
pygmt/exceptions.py
Outdated
Traceback (most recent call last): | ||
... | ||
pygmt...GMTValueError: Invalid .... Explain why it's invalid. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include another test where the input to choices
is an enum like GridRegistration
or GridType
?
msg = ( | ||
f"Invalid grid registration: '{value}'. Should be either " | ||
"GridRegistration.GRIDLINE (0) or GridRegistration.PIXEL (1)." | ||
raise GMTValueError( | ||
value, description="grid registration", choices=GridRegistration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Highlighting this for the above comment, to check that enums like GridRegistration
are formatted properly. I.e. the error should still print "GridRegistration.GRIDLINE (0) or GridRegistration.PIXEL (1)" per #3696 (comment)
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Add new exception GMTValueError. The error message will be like
Address #3984 and #3707.