Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refine handler error logging

Don't log so noisily for known dashi errors
  • Loading branch information...
commit c84183bc6ea807e2deb7fc43c88601eda1c502e4 1 parent ed1d303
David LaBissoniere authored March 01, 2013

Showing 1 changed file with 36 additions and 22 deletions. Show diff stats Hide diff stats

  1. 58  dashi/__init__.py
58  dashi/__init__.py
@@ -466,6 +466,7 @@ def _callback(self, body, message):
466 466
         reply_to = None
467 467
         ret = None
468 468
         err = None
  469
+        err_dict = None
469 470
         try:
470 471
             reply_to = message.headers.get('reply-to')
471 472
 
@@ -493,41 +494,54 @@ def _callback(self, body, message):
493 494
                 log.exception("Type error with handler for %s:%s", self._name, op)
494 495
                 raise BadRequestError("Type error: %s" % str(e))
495 496
             except Exception:
496  
-                log.exception("Error in handler for %s:%s", self._name, op)
497 497
                 raise
498 498
 
499 499
         except Exception:
500 500
             err = sys.exc_info()
501 501
         finally:
  502
+            if err:
  503
+                err_dict, is_known_error = self._wrap_error(err)
  504
+                if is_known_error:
  505
+                    exc_type = err_dict['exc_type']
  506
+                    if exc_type and exc_type.startswith(ERROR_PREFIX):
  507
+                        exc_type = exc_type[len(ERROR_PREFIX):]
  508
+                    log.info("Known '%s' error in handler %s:%s: %s", exc_type,
  509
+                        self._name, op, err_dict['value'])
  510
+                else:
  511
+                    log.error("Unknown '%s' error in handler %s:%s: %s",
  512
+                        err_dict['exc_type'], self._name, op,
  513
+                        err_dict['value'], exc_info=err)
  514
+
502 515
             if reply_to:
503  
-                if err:
504  
-                    tb = "".join(traceback.format_exception(*err))
  516
+                reply = dict(result=ret, error=err_dict)
  517
+                self._dashi.reply(self._conn, reply_to, reply)
505 518
 
506  
-                    # some error types are specific to dashi (not underlying
507  
-                    # service code). These get raised with the same type on
508  
-                    # the client side. Identify them by prefixing the package
509  
-                    # name on the exc_type.
  519
+            message.ack()
510 520
 
511  
-                    exc_type = err[0]
  521
+    def _wrap_error(self, exc_info):
  522
+        tb = "".join(traceback.format_exception(*exc_info))
512 523
 
513  
-                    # Check if there is a dashi exception linked to this custom exception
514  
-                    linked_exception = self._dashi._linked_exceptions.get(exc_type)
515  
-                    if linked_exception:
516  
-                        exc_type = linked_exception
  524
+        # some error types are specific to dashi (not underlying
  525
+        # service code). These get raised with the same type on
  526
+        # the client side. Identify them by prefixing the package
  527
+        # name on the exc_type.
517 528
 
518  
-                    known_type = ERROR_TYPE_MAP.get(exc_type.__name__)
519  
-                    if known_type and exc_type is known_type:
520  
-                        exc_type_name = ERROR_PREFIX + exc_type.__name__
521  
-                    else:
522  
-                        exc_type_name = exc_type.__name__
  529
+        exc_type = exc_info[0]
523 530
 
524  
-                    err = dict(exc_type=exc_type_name, value=str(err[1]),
525  
-                               traceback=tb)
  531
+        # Check if there is a dashi exception linked to this custom exception
  532
+        linked_exception = self._dashi._linked_exceptions.get(exc_type)
  533
+        if linked_exception:
  534
+            exc_type = linked_exception
526 535
 
527  
-                reply = dict(result=ret, error=err)
528  
-                self._dashi.reply(self._conn, reply_to, reply)
  536
+        known_type = ERROR_TYPE_MAP.get(exc_type.__name__)
  537
+        is_known = known_type and exc_type is known_type
  538
+        if is_known:
  539
+            exc_type_name = ERROR_PREFIX + exc_type.__name__
  540
+        else:
  541
+            exc_type_name = exc_type.__name__
529 542
 
530  
-            message.ack()
  543
+        return dict(exc_type=exc_type_name, value=str(exc_info[1]),
  544
+                   traceback=tb), is_known
531 545
 
532 546
     def add_op(self, name, fun, sender_kwarg=None):
533 547
         if not callable(fun):

0 notes on commit c84183b

Please sign in to comment.
Something went wrong with that request. Please try again.