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

Standardize error messages #84

Merged
merged 8 commits into from Feb 26, 2021
Merged

Standardize error messages #84

merged 8 commits into from Feb 26, 2021

Conversation

cosimon
Copy link
Contributor

@cosimon cosimon commented Feb 24, 2021

Description of change

Standardize the error messages and add some information to allow end users to troubleshoot the problem.

QA steps

  • automated tests passing
  • manual qa steps passing (list below)

Risks

Rollback steps

  • revert this branch

Copy link
Contributor

@dmosorast dmosorast left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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.

tap_shopify/__init__.py Show resolved Hide resolved
@@ -0,0 +1,3 @@
class ShopifyError(Exception):
def __init__(self, error, msg=''):
super().__init__('{}\n{}'.format(error.__class__.__name__, msg))
Copy link
Contributor

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

?

Copy link
Contributor Author

@cosimon cosimon Feb 25, 2021

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

@cosimon cosimon merged commit e73c404 into master Feb 26, 2021
@cosimon cosimon deleted the standardize-error-messages branch February 26, 2021 15:53
tmck-code pushed a commit to lexerdev/tap-shopify that referenced this pull request Feb 3, 2022
* 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
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.

None yet

2 participants