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

Proper usage of exceptions under Python3 #939

Closed
ericfrederich opened this issue Nov 14, 2019 · 0 comments · Fixed by #1059
Closed

Proper usage of exceptions under Python3 #939

ericfrederich opened this issue Nov 14, 2019 · 0 comments · Fixed by #1059

Comments

@ericfrederich
Copy link
Contributor

Description of the problem, including code/CLI snippet

Python3 has support to raise from to distinguish between the following circumstances:

  • an exception while handling another exception
  • an exception which is the direct cause of another

For instance when a project doesn't exist as in the code below, you'll see two exceptions:

  • gitlab.exceptions.GitlabHttpError
  • gitlab.exceptions.GitlabGetError
import os
import gitlab

gl = gitlab.Gitlab(
    url=os.environ['GITLAB_URL'],
    private_token=os.environ['GITLAB_TOKEN'],
    api_version="4",
)
gl.auth()

gl.projects.get('non-existent-project')

On Python3 between the two exceptions you'll see the statement: During handling of the above exception, another exception occurred:

This is clearly not the case.

Expected Behavior

You see in the console between the two exceptions:

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

Actual Behavior

You see in the console between the two exceptions:

During handling of the above exception, another exception occurred:

Specifications

  • python-gitlab version: 1.13.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 12.4.1
ericfrederich added a commit to ericfrederich/python-gitlab that referenced this issue Nov 14, 2019
max-wittig added a commit that referenced this issue Apr 7, 2020
chore: use raise..from for chained exceptions (#939)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant