# HG changeset patch # User Marcin Kuzminski # Date 2018-10-02 09:03:22 # Node ID 4de59e0f3132aa2365999342759c43c4febf8fe1 # Parent 9bbd1ad24fa95f10fecb3e0f44d599496a332bd4 exceptions: use python3 compatible exception handling diff --git a/rhodecode/api/exc.py b/rhodecode/api/exc.py --- a/rhodecode/api/exc.py +++ b/rhodecode/api/exc.py @@ -20,7 +20,9 @@ class JSONRPCBaseError(Exception): - pass + def __init__(self, message='', *args): + self.message = message + super(JSONRPCBaseError, self).__init__(message, *args) class JSONRPCError(JSONRPCBaseError): @@ -31,7 +33,8 @@ class JSONRPCValidationError(JSONRPCBase def __init__(self, *args, **kwargs): self.colander_exception = kwargs.pop('colander_exc') - super(JSONRPCValidationError, self).__init__(*args, **kwargs) + super(JSONRPCValidationError, self).__init__( + message=self.colander_exception, *args) class JSONRPCForbidden(JSONRPCBaseError): diff --git a/rhodecode/api/views/repo_api.py b/rhodecode/api/views/repo_api.py --- a/rhodecode/api/views/repo_api.py +++ b/rhodecode/api/views/repo_api.py @@ -33,7 +33,7 @@ from rhodecode.lib import audit_logger from rhodecode.lib import repo_maintenance from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi from rhodecode.lib.celerylib.utils import get_task_id -from rhodecode.lib.utils2 import str2bool, time_to_datetime +from rhodecode.lib.utils2 import str2bool, time_to_datetime, safe_str from rhodecode.lib.ext_json import json from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError from rhodecode.model.changeset_status import ChangesetStatusModel @@ -316,7 +316,7 @@ def get_repo_changeset(request, apiuser, try: cs = repo.get_commit(commit_id=revision, pre_load=pre_load) except TypeError as e: - raise JSONRPCError(e.message) + raise JSONRPCError(safe_str(e)) _cs_json = cs.__json__() _cs_json['diff'] = build_commit_data(cs, changes_details) if changes_details == 'full': @@ -382,7 +382,7 @@ def get_repo_changesets(request, apiuser commits = vcs_repo.get_commits( start_id=start_rev, pre_load=pre_load) except TypeError as e: - raise JSONRPCError(e.message) + raise JSONRPCError(safe_str(e)) except Exception: log.exception('Fetching of commits failed') raise JSONRPCError('Error occurred during commit fetching') @@ -1433,7 +1433,7 @@ def comment_commit( commit_id = repo.scm_instance().get_commit(commit_id=commit_id).raw_id except Exception as e: log.exception('Failed to fetch commit') - raise JSONRPCError(e.message) + raise JSONRPCError(safe_str(e)) if isinstance(userid, Optional): userid = apiuser.user_id diff --git a/rhodecode/apps/_base/__init__.py b/rhodecode/apps/_base/__init__.py --- a/rhodecode/apps/_base/__init__.py +++ b/rhodecode/apps/_base/__init__.py @@ -25,7 +25,8 @@ import operator from pyramid.httpexceptions import HTTPFound, HTTPForbidden, HTTPBadRequest from rhodecode.lib import helpers as h, diffs -from rhodecode.lib.utils2 import StrictAttributeDict, safe_int, datetime_to_time +from rhodecode.lib.utils2 import ( + StrictAttributeDict, safe_int, datetime_to_time, safe_unicode) from rhodecode.lib.vcs.exceptions import RepositoryRequirementError from rhodecode.model import repo from rhodecode.model import repo_group @@ -202,7 +203,7 @@ class RepoAppView(BaseAppView): def _handle_missing_requirements(self, error): log.error( 'Requirements are missing for repository %s: %s', - self.db_repo_name, error.message) + self.db_repo_name, safe_unicode(error)) def _get_local_tmpl_context(self, include_app_defaults=True): _ = self.request.translate diff --git a/rhodecode/apps/ssh_support/tests/test_ssh_wrapper.py b/rhodecode/apps/ssh_support/tests/test_ssh_wrapper.py --- a/rhodecode/apps/ssh_support/tests/test_ssh_wrapper.py +++ b/rhodecode/apps/ssh_support/tests/test_ssh_wrapper.py @@ -28,7 +28,7 @@ class TestSSHWrapper(object): ssh_wrapper.serve( vcs='microsoft-tfs', repo='test-repo', mode=None, user='test', permissions={}, branch_permissions={}) - assert exc_info.value.message == 'Unrecognised VCS: microsoft-tfs' + assert str(exc_info.value) == 'Unrecognised VCS: microsoft-tfs' def test_parse_config(self, ssh_wrapper): config = ssh_wrapper.parse_config(ssh_wrapper.ini_path)