Bug 1255986 - [moztest] Safe-guard structured logging for exceptions from bad handlers. r?jgraham draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 03 Jun 2016 22:20:59 +0200
changeset 379680 80612bf6de7484b6bb632612a05f2eb0d755a326
parent 379679 52b0a8a476d1b34c4e925224f0be1d5bedab2e06
child 380114 0d886ccf6bba6b839493e49f1957954b9988c486
push id21020
push userbmo:hskupin@gmail.com
push dateThu, 16 Jun 2016 15:19:03 +0000
reviewersjgraham
bugs1255986
milestone50.0a1
Bug 1255986 - [moztest] Safe-guard structured logging for exceptions from bad handlers. r?jgraham Any exception which gets thrown by a log handler while test results are getting generated, should not cause test harnesses to stop immediately. To achive that the exception gets logged appropriately and not propagated up the stack. MozReview-Commit-ID: ChyYxApYSGx
testing/mozbase/mozlog/mozlog/structuredlog.py
--- a/testing/mozbase/mozlog/mozlog/structuredlog.py
+++ b/testing/mozbase/mozlog/mozlog/structuredlog.py
@@ -195,24 +195,32 @@ class StructuredLogger(object):
     def _log_data(self, action, data=None):
         if data is None:
             data = {}
 
         log_data = self._make_log_data(action, data)
         self._handle_log(log_data)
 
     def _handle_log(self, data):
+        exc = None
+
         with self._lock:
             if self.component_filter:
                 data = self.component_filter(data)
                 if data is None:
                     return
 
             for handler in self.handlers:
-                handler(data)
+                try:
+                    handler(data)
+                except Exception:
+                    exc = True
+
+        if exc:
+            self.error('Failure calling log handler.', exc_info=True)
 
     def _make_log_data(self, action, data):
         all_data = {"action": action,
                     "time": int(time.time() * 1000),
                     "thread": current_thread().name,
                     "pid": current_process().pid,
                     "source": self.name}
         if self.component: