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

Use "raise from" #455

Merged
merged 2 commits into from
Aug 7, 2023
Merged

Use "raise from" #455

merged 2 commits into from
Aug 7, 2023

Conversation

m-aciek
Copy link
Contributor

@m-aciek m-aciek commented Aug 6, 2023

Proposed changes

For wlc exceptions indicate that an exception is a direct consequence of another (see exception chaining).

In practice it changes a following example traceback:

  File "projects/wlc/wlc/__init__.py", line 201, in invoke_request
    response.raise_for_status()
  File ".pyenv/versions/wlc/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://hosted.weblate.org/api/projects/python-docs/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "projects/python-docs-weblate/.update-translation.py", line 69, in <module>
    _update_translation(options.language, weblate_key=weblate_key)
  …
  File "projects/wlc/wlc/__init__.py", line 128, in process_error
    raise WeblateThrottlingError
wlc.WeblateThrottlingError: Throttling on the server.

into:

Traceback (most recent call last):
  File "projects/wlc/wlc/__init__.py", line 201, in invoke_request
    response.raise_for_status()
  File ".pyenv/versions/wlc/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://hosted.weblate.org/api/projects/python-docs/

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "projects/python-docs-weblate/.update-translation.py", line 69, in <module>
    _update_translation(options.language, weblate_key=weblate_key)
  …
  File "projects/wlc/wlc/__init__.py", line 128, in process_error
    raise WeblateThrottlingError from error
wlc.WeblateThrottlingError: Throttling on the server.

(Note the linking phrase between the tracebacks.)

Checklist

  • Lint and unit tests pass locally with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added documentation to describe my feature.
  • I have squashed my commits into logic units.
  • I have described the changes in the commit messages.

@codecov
Copy link

codecov bot commented Aug 6, 2023

Codecov Report

Merging #455 (7512c2a) into main (4d1c0a7) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #455   +/-   ##
=======================================
  Coverage   98.97%   98.97%           
=======================================
  Files           6        6           
  Lines        1655     1655           
  Branches      217      217           
=======================================
  Hits         1638     1638           
  Misses          8        8           
  Partials        9        9           
Files Changed Coverage Δ
wlc/__init__.py 97.57% <100.00%> (ø)

@nijel
Copy link
Member

nijel commented Aug 7, 2023

It now has conflicts after changes from your other PR. Moreover, can you please enable corresponding ruff checks so that this is linted?

@nijel nijel merged commit 1fbfced into WeblateOrg:main Aug 7, 2023
24 checks passed
@nijel
Copy link
Member

nijel commented Aug 7, 2023

Merged, thanks for your contribution!

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.

2 participants