diff --git a/rhodecode/api/__init__.py b/rhodecode/api/__init__.py --- a/rhodecode/api/__init__.py +++ b/rhodecode/api/__init__.py @@ -21,6 +21,7 @@ import inspect import itertools import logging +import sys import types import fnmatch @@ -38,6 +39,7 @@ from rhodecode.api.exc import ( from rhodecode.apps._base import TemplateArgs from rhodecode.lib.auth import AuthUser from rhodecode.lib.base import get_ip_addr, attach_context_attributes +from rhodecode.lib.exc_tracking import store_exception from rhodecode.lib.ext_json import json from rhodecode.lib.utils2 import safe_str from rhodecode.lib.plugins.utils import get_plugin_settings @@ -140,7 +142,6 @@ def jsonrpc_error(request, message, reti def exception_view(exc, request): rpc_id = getattr(request, 'rpc_id', None) - fault_message = 'undefined error' if isinstance(exc, JSONRPCError): fault_message = safe_str(exc.message) log.debug('json-rpc error rpc_id:%s "%s"', rpc_id, fault_message) @@ -170,6 +171,10 @@ def exception_view(exc, request): fault_message = "No such method: {}. Similar methods: {}".format( method, similar) + else: + fault_message = 'undefined error' + exc_info = exc.exc_info() + store_exception(id(exc_info), exc_info, prefix='rhodecode-api') return jsonrpc_error(request, fault_message, rpc_id) @@ -292,8 +297,10 @@ def request_view(request): raise except Exception: log.exception('Unhandled exception occurred on api call: %s', func) - return jsonrpc_error(request, retid=request.rpc_id, - message='Internal server error') + exc_info = sys.exc_info() + store_exception(id(exc_info), exc_info, prefix='rhodecode-api') + return jsonrpc_error( + request, retid=request.rpc_id, message='Internal server error') def setup_request(request): @@ -414,8 +421,7 @@ def add_jsonrpc_method(config, view, **k if method is None: raise ConfigurationError( - 'Cannot register a JSON-RPC method without specifying the ' - '"method"') + 'Cannot register a JSON-RPC method without specifying the "method"') # we define custom predicate, to enable to detect conflicting methods, # those predicates are kind of "translation" from the decorator variables @@ -524,6 +530,7 @@ def includeme(config): # match filter by given method only config.add_view_predicate('jsonrpc_method', MethodPredicate) + config.add_view_predicate('jsonrpc_method_not_found', NotFoundPredicate) config.add_renderer(DEFAULT_RENDERER, ExtJsonRenderer( serializer=json.dumps, indent=4)) @@ -538,5 +545,4 @@ def includeme(config): config.scan(plugin_module, ignore='rhodecode.api.tests') # register some exception handling view config.add_view(exception_view, context=JSONRPCBaseError) - config.add_view_predicate('jsonrpc_method_not_found', NotFoundPredicate) config.add_notfound_view(exception_view, jsonrpc_method_not_found=True) diff --git a/rhodecode/lib/celerylib/loader.py b/rhodecode/lib/celerylib/loader.py --- a/rhodecode/lib/celerylib/loader.py +++ b/rhodecode/lib/celerylib/loader.py @@ -170,7 +170,7 @@ def task_failure_signal( # simulate sys.exc_info() exc_info = (einfo.type, einfo.exception, einfo.tb) - store_exception(id(exc_info), exc_info, prefix='celery_rhodecode') + store_exception(id(exc_info), exc_info, prefix='rhodecode-celery') closer = celery_app.conf['PYRAMID_CLOSER'] if closer: diff --git a/rhodecode/lib/exc_tracking.py b/rhodecode/lib/exc_tracking.py --- a/rhodecode/lib/exc_tracking.py +++ b/rhodecode/lib/exc_tracking.py @@ -104,7 +104,7 @@ def store_exception(exc_id, exc_info, pr try: exc_type_name, exc_traceback = _prepare_exception(exc_info) _store_exception(exc_id=exc_id, exc_type_name=exc_type_name, - exc_traceback=exc_traceback, prefix=prefix) + exc_traceback=exc_traceback, prefix=prefix) except Exception: log.exception('Failed to store exception `%s` information', exc_id) # there's no way this can fail, it will crash server badly if it does.