Explorar o código

Implement __str__ so code and text of RPCError are logged
This is helpful for troubleshooting issues like #627 where the
traceback doesn't show the contents of the RPCError.

2015-06-29 10:11:38 RPCError
becomes:
2015-06-29 10:11:38 RPCError: code=20, text:'NO_FILE: /nonexistent'

Mike Naberezny %!s(int64=9) %!d(string=hai) anos
pai
achega
3149e16e62
Modificáronse 2 ficheiros con 10 adicións e 0 borrados
  1. 7 0
      supervisor/tests/test_xmlrpc.py
  2. 3 0
      supervisor/xmlrpc.py

+ 7 - 0
supervisor/tests/test_xmlrpc.py

@@ -36,6 +36,13 @@ class RPCErrorTests(unittest.TestCase):
         e = self._makeOne(xmlrpc.Faults.FAILED, 'oops')
         self.assertEqual(e.text, 'FAILED: oops')
 
+    def test___str___shows_code_and_text(self):
+        from supervisor import xmlrpc
+        e = self._makeOne(xmlrpc.Faults.NO_FILE, '/nonexistent')
+        self.assertEqual(str(e),
+            "code=%r, text='NO_FILE: /nonexistent'" % xmlrpc.Faults.NO_FILE
+            )
+
 class XMLRPCMarshallingTests(unittest.TestCase):
     def test_xmlrpc_marshal(self):
         from supervisor import xmlrpc

+ 3 - 0
supervisor/xmlrpc.py

@@ -57,6 +57,9 @@ class RPCError(Exception):
         if extra is not None:
             self.text = '%s: %s' % (self.text, extra)
 
+    def __str__(self):
+        return 'code=%r, text=%r' % (self.code, self.text)
+
 class DeferredXMLRPCResponse:
     """ A medusa producer that implements a deferred callback; requires
     a subclass of asynchat.async_chat that handles NOT_DONE_YET sentinel """