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

Commit6749859

Browse files
authored
Merge pull request#1059 from python-gitlab/fix/raise-from
chore: use raise..from for chained exceptions (#939)
2 parents5979750 +79fef26 commit6749859

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
@@ -606,10 +606,10 @@ def http_get(self, path, query_data=None, streamed=False, raw=False, **kwargs):
606606
):
607607
try:
608608
returnresult.json()
609-
exceptException:
609+
exceptExceptionase:
610610
raiseGitlabParsingError(
611611
error_message="Failed to parse the server message"
612-
)
612+
)frome
613613
else:
614614
returnresult
615615

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

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

728732
defhttp_delete(self,path,**kwargs):
729733
"""Make a PUT request to the Gitlab server.
@@ -789,8 +793,10 @@ def _query(self, url, query_data=None, **kwargs):
789793

790794
try:
791795
self._data=result.json()
792-
exceptException:
793-
raiseGitlabParsingError(error_message="Failed to parse the server message")
796+
exceptExceptionase:
797+
raiseGitlabParsingError(
798+
error_message="Failed to parse the server message"
799+
)frome
794800

795801
self._current=0
796802

‎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
@@ -274,7 +274,7 @@ def wrapped_f(*args, **kwargs):
274274
try:
275275
returnf(*args,**kwargs)
276276
exceptGitlabHttpErrorase:
277-
raiseerror(e.error_message,e.response_code,e.response_body)
277+
raiseerror(e.error_message,e.response_code,e.response_body)frome
278278

279279
returnwrapped_f
280280

‎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
@@ -2843,14 +2843,14 @@ def set_release_description(self, description, **kwargs):
28432843
path,post_data=data,**kwargs
28442844
)
28452845
exceptexc.GitlabHttpErrorase:
2846-
raiseexc.GitlabCreateError(e.response_code,e.error_message)
2846+
raiseexc.GitlabCreateError(e.response_code,e.error_message)frome
28472847
else:
28482848
try:
28492849
server_data=self.manager.gitlab.http_put(
28502850
path,post_data=data,**kwargs
28512851
)
28522852
exceptexc.GitlabHttpErrorase:
2853-
raiseexc.GitlabUpdateError(e.response_code,e.error_message)
2853+
raiseexc.GitlabUpdateError(e.response_code,e.error_message)frome
28542854
self.release=server_data
28552855

28562856

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp