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

chore: Improve errors.py #100

Merged
merged 19 commits into from
Jun 20, 2022
Merged

chore: Improve errors.py #100

merged 19 commits into from
Jun 20, 2022

Conversation

bgrant
Copy link
Collaborator

@bgrant bgrant commented Jun 6, 2022

  • Let ServerError take an additional_info argument

  • Use f-strings throughout errors.py

  • Use enum value rather than bare int for an error code

  • Add some unit tests for errors.py to bump up coverage

  • Bump coverage check to 91%

  • Fix a Sphinx configuration error that appears with a new version of Sphinx (to get the PR checks to pass)

  • Update CHANGELOG.md

  • Update README.md (as needed)

  • New dependencies were added to requirements.txt or requirements-dev.txt

  • pip install succeeds with a clean virtualenv

  • There are new or modified tests that cover changes

  • Test coverage is maintained or expanded

@bgrant bgrant requested review from dshafer and demianbrecht June 10, 2022 20:51
@@ -113,7 +112,7 @@ def __init__(self, additional_info=None):
http.client.responses.get(http.client.NOT_FOUND),
)
if additional_info:
error_message += " : " + additional_info
Copy link
Collaborator Author

@bgrant bgrant Jun 13, 2022

Choose a reason for hiding this comment

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

This change (removing a space from the message to make it consistent with the other messages) requires a small test fix in our downstream service.

@@ -170,7 +173,7 @@ def __init__(self, additional_info=None):
class ClientErrorResponseWrapper(ClientError):
def __init__(self, response):
error_code = response.status_code
error_message = response.content
error_message = response.content.decode()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

error_message is bytestring unless we do this. Maybe this wasn't an issue until Python 3?

@@ -84,7 +84,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Letting language be None causes an error with a new version of Sphinx.

error_code, error_message = LOGGED_SERVER_ERROR
error_message = error_message.format(uuid.uuid4())
if additional_info:
error_message += f": {additional_info}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe that this error_message is returned directly to the client. Should we make it so that the additional_info only appears in logs, and the client only gets the opaque error UUID?

Requires running tests with logging on
@@ -21,8 +21,6 @@

ROOT_URLCONF = "tests.urls"

TEST_RUNNER = "tests.testutils.NoLoggingTestRunner"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did this so I could test the logging on the ServerError

@smholloway smholloway merged commit a28b543 into main Jun 20, 2022
@smholloway smholloway deleted the chore/improve-servererror branch June 20, 2022 18:11
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.

3 participants