##// END OF EJS Templates
exc-tracker: store API based exceptions and fix prefixes to no use _
marcink -
r3335:3f5d13e1 default
parent child Browse files
Show More
@@ -21,6 +21,7 b''
21 import inspect
21 import inspect
22 import itertools
22 import itertools
23 import logging
23 import logging
24 import sys
24 import types
25 import types
25 import fnmatch
26 import fnmatch
26
27
@@ -38,6 +39,7 b' from rhodecode.api.exc import ('
38 from rhodecode.apps._base import TemplateArgs
39 from rhodecode.apps._base import TemplateArgs
39 from rhodecode.lib.auth import AuthUser
40 from rhodecode.lib.auth import AuthUser
40 from rhodecode.lib.base import get_ip_addr, attach_context_attributes
41 from rhodecode.lib.base import get_ip_addr, attach_context_attributes
42 from rhodecode.lib.exc_tracking import store_exception
41 from rhodecode.lib.ext_json import json
43 from rhodecode.lib.ext_json import json
42 from rhodecode.lib.utils2 import safe_str
44 from rhodecode.lib.utils2 import safe_str
43 from rhodecode.lib.plugins.utils import get_plugin_settings
45 from rhodecode.lib.plugins.utils import get_plugin_settings
@@ -140,7 +142,6 b' def jsonrpc_error(request, message, reti'
140 def exception_view(exc, request):
142 def exception_view(exc, request):
141 rpc_id = getattr(request, 'rpc_id', None)
143 rpc_id = getattr(request, 'rpc_id', None)
142
144
143 fault_message = 'undefined error'
144 if isinstance(exc, JSONRPCError):
145 if isinstance(exc, JSONRPCError):
145 fault_message = safe_str(exc.message)
146 fault_message = safe_str(exc.message)
146 log.debug('json-rpc error rpc_id:%s "%s"', rpc_id, fault_message)
147 log.debug('json-rpc error rpc_id:%s "%s"', rpc_id, fault_message)
@@ -170,6 +171,10 b' def exception_view(exc, request):'
170
171
171 fault_message = "No such method: {}. Similar methods: {}".format(
172 fault_message = "No such method: {}. Similar methods: {}".format(
172 method, similar)
173 method, similar)
174 else:
175 fault_message = 'undefined error'
176 exc_info = exc.exc_info()
177 store_exception(id(exc_info), exc_info, prefix='rhodecode-api')
173
178
174 return jsonrpc_error(request, fault_message, rpc_id)
179 return jsonrpc_error(request, fault_message, rpc_id)
175
180
@@ -292,8 +297,10 b' def request_view(request):'
292 raise
297 raise
293 except Exception:
298 except Exception:
294 log.exception('Unhandled exception occurred on api call: %s', func)
299 log.exception('Unhandled exception occurred on api call: %s', func)
295 return jsonrpc_error(request, retid=request.rpc_id,
300 exc_info = sys.exc_info()
296 message='Internal server error')
301 store_exception(id(exc_info), exc_info, prefix='rhodecode-api')
302 return jsonrpc_error(
303 request, retid=request.rpc_id, message='Internal server error')
297
304
298
305
299 def setup_request(request):
306 def setup_request(request):
@@ -414,8 +421,7 b' def add_jsonrpc_method(config, view, **k'
414
421
415 if method is None:
422 if method is None:
416 raise ConfigurationError(
423 raise ConfigurationError(
417 'Cannot register a JSON-RPC method without specifying the '
424 'Cannot register a JSON-RPC method without specifying the "method"')
418 '"method"')
419
425
420 # we define custom predicate, to enable to detect conflicting methods,
426 # we define custom predicate, to enable to detect conflicting methods,
421 # those predicates are kind of "translation" from the decorator variables
427 # those predicates are kind of "translation" from the decorator variables
@@ -524,6 +530,7 b' def includeme(config):'
524
530
525 # match filter by given method only
531 # match filter by given method only
526 config.add_view_predicate('jsonrpc_method', MethodPredicate)
532 config.add_view_predicate('jsonrpc_method', MethodPredicate)
533 config.add_view_predicate('jsonrpc_method_not_found', NotFoundPredicate)
527
534
528 config.add_renderer(DEFAULT_RENDERER, ExtJsonRenderer(
535 config.add_renderer(DEFAULT_RENDERER, ExtJsonRenderer(
529 serializer=json.dumps, indent=4))
536 serializer=json.dumps, indent=4))
@@ -538,5 +545,4 b' def includeme(config):'
538 config.scan(plugin_module, ignore='rhodecode.api.tests')
545 config.scan(plugin_module, ignore='rhodecode.api.tests')
539 # register some exception handling view
546 # register some exception handling view
540 config.add_view(exception_view, context=JSONRPCBaseError)
547 config.add_view(exception_view, context=JSONRPCBaseError)
541 config.add_view_predicate('jsonrpc_method_not_found', NotFoundPredicate)
542 config.add_notfound_view(exception_view, jsonrpc_method_not_found=True)
548 config.add_notfound_view(exception_view, jsonrpc_method_not_found=True)
@@ -170,7 +170,7 b' def task_failure_signal('
170
170
171 # simulate sys.exc_info()
171 # simulate sys.exc_info()
172 exc_info = (einfo.type, einfo.exception, einfo.tb)
172 exc_info = (einfo.type, einfo.exception, einfo.tb)
173 store_exception(id(exc_info), exc_info, prefix='celery_rhodecode')
173 store_exception(id(exc_info), exc_info, prefix='rhodecode-celery')
174
174
175 closer = celery_app.conf['PYRAMID_CLOSER']
175 closer = celery_app.conf['PYRAMID_CLOSER']
176 if closer:
176 if closer:
@@ -104,7 +104,7 b' def store_exception(exc_id, exc_info, pr'
104 try:
104 try:
105 exc_type_name, exc_traceback = _prepare_exception(exc_info)
105 exc_type_name, exc_traceback = _prepare_exception(exc_info)
106 _store_exception(exc_id=exc_id, exc_type_name=exc_type_name,
106 _store_exception(exc_id=exc_id, exc_type_name=exc_type_name,
107 exc_traceback=exc_traceback, prefix=prefix)
107 exc_traceback=exc_traceback, prefix=prefix)
108 except Exception:
108 except Exception:
109 log.exception('Failed to store exception `%s` information', exc_id)
109 log.exception('Failed to store exception `%s` information', exc_id)
110 # there's no way this can fail, it will crash server badly if it does.
110 # there's no way this can fail, it will crash server badly if it does.
General Comments 0
You need to be logged in to leave comments. Login now