Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79fef26

Browse files
committed
chore: use raise..from for chained exceptions (#939)
1 parentc5904c4 commit79fef26

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

‎gitlab/__init__.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,10 @@ def http_get(self, path, query_data=None, streamed=False, raw=False, **kwargs):
605605
):
606606
try:
607607
returnresult.json()
608-
exceptException:
608+
exceptExceptionase:
609609
raiseGitlabParsingError(
610610
error_message="Failed to parse the server message"
611-
)
611+
)frome
612612
else:
613613
returnresult
614614

@@ -685,8 +685,10 @@ def http_post(self, path, query_data=None, post_data=None, files=None, **kwargs)
685685
try:
686686
ifresult.headers.get("Content-Type",None)=="application/json":
687687
returnresult.json()
688-
exceptException:
689-
raiseGitlabParsingError(error_message="Failed to parse the server message")
688+
exceptExceptionase:
689+
raiseGitlabParsingError(
690+
error_message="Failed to parse the server message"
691+
)frome
690692
returnresult
691693

692694
defhttp_put(self,path,query_data=None,post_data=None,files=None,**kwargs):
@@ -721,8 +723,10 @@ def http_put(self, path, query_data=None, post_data=None, files=None, **kwargs):
721723
)
722724
try:
723725
returnresult.json()
724-
exceptException:
725-
raiseGitlabParsingError(error_message="Failed to parse the server message")
726+
exceptExceptionase:
727+
raiseGitlabParsingError(
728+
error_message="Failed to parse the server message"
729+
)frome
726730

727731
defhttp_delete(self,path,**kwargs):
728732
"""Make a PUT request to the Gitlab server.
@@ -788,8 +792,10 @@ def _query(self, url, query_data=None, **kwargs):
788792

789793
try:
790794
self._data=result.json()
791-
exceptException:
792-
raiseGitlabParsingError(error_message="Failed to parse the server message")
795+
exceptExceptionase:
796+
raiseGitlabParsingError(
797+
error_message="Failed to parse the server message"
798+
)frome
793799

794800
self._current=0
795801

‎gitlab/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ def __init__(self, gitlab_id=None, config_files=None):
6060
ifself.gitlab_idisNone:
6161
try:
6262
self.gitlab_id=self._config.get("global","default")
63-
exceptException:
63+
exceptExceptionase:
6464
raiseGitlabIDError(
6565
"Impossible to get the gitlab id (not specified in config file)"
66-
)
66+
)frome
6767

6868
try:
6969
self.url=self._config.get(self.gitlab_id,"url")
70-
exceptException:
70+
exceptExceptionase:
7171
raiseGitlabDataError(
7272
"Impossible to get gitlab informations from "
7373
"configuration (%s)"%self.gitlab_id
74-
)
74+
)frome
7575

7676
self.ssl_verify=True
7777
try:

‎gitlab/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def wrapped_f(*args, **kwargs):
270270
try:
271271
returnf(*args,**kwargs)
272272
exceptGitlabHttpErrorase:
273-
raiseerror(e.error_message,e.response_code,e.response_body)
273+
raiseerror(e.error_message,e.response_code,e.response_body)frome
274274

275275
returnwrapped_f
276276

‎gitlab/tests/test_exceptions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
importunittest
2+
3+
fromgitlabimportexceptions
4+
5+
6+
classTestExceptions(unittest.TestCase):
7+
deftest_error_raises_from_http_error(self):
8+
"""Methods decorated with @on_http_error should raise from GitlabHttpError."""
9+
10+
classTestError(Exception):
11+
pass
12+
13+
@exceptions.on_http_error(TestError)
14+
defraise_error_from_http_error():
15+
raiseexceptions.GitlabHttpError
16+
17+
withself.assertRaises(TestError)ascontext:
18+
raise_error_from_http_error()
19+
self.assertIsInstance(context.exception.__cause__,exceptions.GitlabHttpError)

‎gitlab/v4/objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,14 +2720,14 @@ def set_release_description(self, description, **kwargs):
27202720
path,post_data=data,**kwargs
27212721
)
27222722
exceptexc.GitlabHttpErrorase:
2723-
raiseexc.GitlabCreateError(e.response_code,e.error_message)
2723+
raiseexc.GitlabCreateError(e.response_code,e.error_message)frome
27242724
else:
27252725
try:
27262726
server_data=self.manager.gitlab.http_put(
27272727
path,post_data=data,**kwargs
27282728
)
27292729
exceptexc.GitlabHttpErrorase:
2730-
raiseexc.GitlabUpdateError(e.response_code,e.error_message)
2730+
raiseexc.GitlabUpdateError(e.response_code,e.error_message)frome
27312731
self.release=server_data
27322732

27332733

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp