Permalink
Browse files

Refine handler error logging

Don't log so noisily for known dashi errors
  • Loading branch information...
1 parent ed1d303 commit c84183bc6ea807e2deb7fc43c88601eda1c502e4 @labisso labisso committed Mar 1, 2013
Showing with 36 additions and 22 deletions.
  1. +36 −22 dashi/__init__.py
View
@@ -466,6 +466,7 @@ def _callback(self, body, message):
reply_to = None
ret = None
err = None
+ err_dict = None
try:
reply_to = message.headers.get('reply-to')
@@ -493,41 +494,54 @@ def _callback(self, body, message):
log.exception("Type error with handler for %s:%s", self._name, op)
raise BadRequestError("Type error: %s" % str(e))
except Exception:
- log.exception("Error in handler for %s:%s", self._name, op)
raise
except Exception:
err = sys.exc_info()
finally:
+ if err:
+ err_dict, is_known_error = self._wrap_error(err)
+ if is_known_error:
+ exc_type = err_dict['exc_type']
+ if exc_type and exc_type.startswith(ERROR_PREFIX):
+ exc_type = exc_type[len(ERROR_PREFIX):]
+ log.info("Known '%s' error in handler %s:%s: %s", exc_type,
+ self._name, op, err_dict['value'])
+ else:
+ log.error("Unknown '%s' error in handler %s:%s: %s",
+ err_dict['exc_type'], self._name, op,
+ err_dict['value'], exc_info=err)
+
if reply_to:
- if err:
- tb = "".join(traceback.format_exception(*err))
+ reply = dict(result=ret, error=err_dict)
+ self._dashi.reply(self._conn, reply_to, reply)
- # some error types are specific to dashi (not underlying
- # service code). These get raised with the same type on
- # the client side. Identify them by prefixing the package
- # name on the exc_type.
+ message.ack()
- exc_type = err[0]
+ def _wrap_error(self, exc_info):
+ tb = "".join(traceback.format_exception(*exc_info))
- # Check if there is a dashi exception linked to this custom exception
- linked_exception = self._dashi._linked_exceptions.get(exc_type)
- if linked_exception:
- exc_type = linked_exception
+ # some error types are specific to dashi (not underlying
+ # service code). These get raised with the same type on
+ # the client side. Identify them by prefixing the package
+ # name on the exc_type.
- known_type = ERROR_TYPE_MAP.get(exc_type.__name__)
- if known_type and exc_type is known_type:
- exc_type_name = ERROR_PREFIX + exc_type.__name__
- else:
- exc_type_name = exc_type.__name__
+ exc_type = exc_info[0]
- err = dict(exc_type=exc_type_name, value=str(err[1]),
- traceback=tb)
+ # Check if there is a dashi exception linked to this custom exception
+ linked_exception = self._dashi._linked_exceptions.get(exc_type)
+ if linked_exception:
+ exc_type = linked_exception
- reply = dict(result=ret, error=err)
- self._dashi.reply(self._conn, reply_to, reply)
+ known_type = ERROR_TYPE_MAP.get(exc_type.__name__)
+ is_known = known_type and exc_type is known_type
+ if is_known:
+ exc_type_name = ERROR_PREFIX + exc_type.__name__
+ else:
+ exc_type_name = exc_type.__name__
- message.ack()
+ return dict(exc_type=exc_type_name, value=str(exc_info[1]),
+ traceback=tb), is_known
def add_op(self, name, fun, sender_kwarg=None):
if not callable(fun):

0 comments on commit c84183b

Please sign in to comment.