exceptions: use python3 compatible exception handling
marcink -
r3104:4de59e0f default
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -20,7 +20,9
20
20
21
21
22 class JSONRPCBaseError(Exception):
22 class JSONRPCBaseError(Exception):
23 pass
23 def __init__(self, message='', *args):
24 self.message = message
25 super(JSONRPCBaseError, self).__init__(message, *args)
24
26
25
27
26 class JSONRPCError(JSONRPCBaseError):
28 class JSONRPCError(JSONRPCBaseError):
@@ -31,7 +33,8
31
33
32 def __init__(self, *args, **kwargs):
34 def __init__(self, *args, **kwargs):
33 self.colander_exception = kwargs.pop('colander_exc')
35 self.colander_exception = kwargs.pop('colander_exc')
34 super(JSONRPCValidationError, self).__init__(*args, **kwargs)
36 super(JSONRPCValidationError, self).__init__(
37 message=self.colander_exception, *args)
35
38
36
39
37 class JSONRPCForbidden(JSONRPCBaseError):
40 class JSONRPCForbidden(JSONRPCBaseError):
@@ -33,7 +33,7
33 from rhodecode.lib import repo_maintenance
33 from rhodecode.lib import repo_maintenance
34 from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi
34 from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi
35 from rhodecode.lib.celerylib.utils import get_task_id
35 from rhodecode.lib.celerylib.utils import get_task_id
36 from rhodecode.lib.utils2 import str2bool, time_to_datetime
36 from rhodecode.lib.utils2 import str2bool, time_to_datetime, safe_str
37 from rhodecode.lib.ext_json import json
37 from rhodecode.lib.ext_json import json
38 from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError
38 from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError
39 from rhodecode.model.changeset_status import ChangesetStatusModel
39 from rhodecode.model.changeset_status import ChangesetStatusModel
@@ -316,7 +316,7
316 try:
316 try:
317 cs = repo.get_commit(commit_id=revision, pre_load=pre_load)
317 cs = repo.get_commit(commit_id=revision, pre_load=pre_load)
318 except TypeError as e:
318 except TypeError as e:
319 raise JSONRPCError(e.message)
319 raise JSONRPCError(safe_str(e))
320 _cs_json = cs.__json__()
320 _cs_json = cs.__json__()
321 _cs_json['diff'] = build_commit_data(cs, changes_details)
321 _cs_json['diff'] = build_commit_data(cs, changes_details)
322 if changes_details == 'full':
322 if changes_details == 'full':
@@ -382,7 +382,7
382 commits = vcs_repo.get_commits(
382 commits = vcs_repo.get_commits(
383 start_id=start_rev, pre_load=pre_load)
383 start_id=start_rev, pre_load=pre_load)
384 except TypeError as e:
384 except TypeError as e:
385 raise JSONRPCError(e.message)
385 raise JSONRPCError(safe_str(e))
386 except Exception:
386 except Exception:
387 log.exception('Fetching of commits failed')
387 log.exception('Fetching of commits failed')
388 raise JSONRPCError('Error occurred during commit fetching')
388 raise JSONRPCError('Error occurred during commit fetching')
@@ -1433,7 +1433,7
1433 commit_id = repo.scm_instance().get_commit(commit_id=commit_id).raw_id
1433 commit_id = repo.scm_instance().get_commit(commit_id=commit_id).raw_id
1434 except Exception as e:
1434 except Exception as e:
1435 log.exception('Failed to fetch commit')
1435 log.exception('Failed to fetch commit')
1436 raise JSONRPCError(e.message)
1436 raise JSONRPCError(safe_str(e))
1437
1437
1438 if isinstance(userid, Optional):
1438 if isinstance(userid, Optional):
1439 userid = apiuser.user_id
1439 userid = apiuser.user_id
@@ -25,7 +25,8
25 from pyramid.httpexceptions import HTTPFound, HTTPForbidden, HTTPBadRequest
25 from pyramid.httpexceptions import HTTPFound, HTTPForbidden, HTTPBadRequest
26
26
27 from rhodecode.lib import helpers as h, diffs
27 from rhodecode.lib import helpers as h, diffs
28 from rhodecode.lib.utils2 import StrictAttributeDict, safe_int, datetime_to_time
28 from rhodecode.lib.utils2 import (
29 StrictAttributeDict, safe_int, datetime_to_time, safe_unicode)
29 from rhodecode.lib.vcs.exceptions import RepositoryRequirementError
30 from rhodecode.lib.vcs.exceptions import RepositoryRequirementError
30 from rhodecode.model import repo
31 from rhodecode.model import repo
31 from rhodecode.model import repo_group
32 from rhodecode.model import repo_group
@@ -202,7 +203,7
202 def _handle_missing_requirements(self, error):
203 def _handle_missing_requirements(self, error):
203 log.error(
204 log.error(
204 'Requirements are missing for repository %s: %s',
205 'Requirements are missing for repository %s: %s',
205 self.db_repo_name, error.message)
206 self.db_repo_name, safe_unicode(error))
206
207
207 def _get_local_tmpl_context(self, include_app_defaults=True):
208 def _get_local_tmpl_context(self, include_app_defaults=True):
208 _ = self.request.translate
209 _ = self.request.translate
@@ -28,7 +28,7
28 ssh_wrapper.serve(
28 ssh_wrapper.serve(
29 vcs='microsoft-tfs', repo='test-repo', mode=None, user='test',
29 vcs='microsoft-tfs', repo='test-repo', mode=None, user='test',
30 permissions={}, branch_permissions={})
30 permissions={}, branch_permissions={})
31 assert exc_info.value.message == 'Unrecognised VCS: microsoft-tfs'
31 assert str(exc_info.value) == 'Unrecognised VCS: microsoft-tfs'
32
32
33 def test_parse_config(self, ssh_wrapper):
33 def test_parse_config(self, ssh_wrapper):
34 config = ssh_wrapper.parse_config(ssh_wrapper.ini_path)
34 config = ssh_wrapper.parse_config(ssh_wrapper.ini_path)
Comments 0
You need to be logged in to leave comments. Login now