-
Notifications
You must be signed in to change notification settings - Fork 89
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
Standardize error messages #84
Conversation
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.
Just one comment that's remarking on the try-catch stuff, one comment that I think should be addressed with a change, and one comment that I'm unsure about.
body = json.loads(body_json) | ||
msg = body.get('errors') | ||
finally: | ||
raise ShopifyError(exc, msg) from exc |
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.
Interesting, just to get this down, I wasn't sure this would work, but it seems like any exception thrown from JSON parsing will just get swallowed implicitly, and the true exception will bubble up. Nice.
>>> try:
... raise Exception("1")
... except Exception as ex:
... try:
... raise Exception("2")
... finally:
... raise Exception("3") from ex
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
Exception: 1
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
Exception: 3
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.
Yup, I was skeptical of it too but it works.
@@ -0,0 +1,3 @@ | |||
class ShopifyError(Exception): | |||
def __init__(self, error, msg=''): | |||
super().__init__('{}\n{}'.format(error.__class__.__name__, msg)) |
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.
So will this, e.g., come out like
CRITICAL pyactiveresource.connection.ResourceNotFound
CRITICAL Ensure shop is entered correctly
?
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.
The full namespace of the exception is not printed.
CRITICAL ResourceNotFound
CRITICAL Ensure shop is entered correctly
* Normalize the error messages * Broaden the exception * Put error message on a single line * Add helpful text in case of `ResourceNotFound` * Change top level exception logger to log lines individually * Add helpful message in case of UnauthorizedAccess error * Raise exceptions from causal exception * Bump singer-python to 5.11.0 and use `handle_top_exception` again
Description of change
Standardize the error messages and add some information to allow end users to troubleshoot the problem.
QA steps
Risks
Rollback steps