[MERGE] Log smart server errors in the trace file

Andrew Bennetts andrew at canonical.com
Tue Jul 17 08:05:22 BST 2007


The attached merge directive makes the smart server log errors into the trace
file.  This is more verbose than ideal (like with the command line, not all
error responses deserve a traceback), but at the moment we're too extreme in the
other direction.  This will make debugging test failures, and failures in live
systems, much easier.

-Andrew.

p.s.  Thanks to Martin for showing me that I can just type "Attach: foo" in vim
      and mutt will do the right thing.  Expect less missing attachments from me
      now! :)

-------------- next part --------------
# Bazaar merge directive format 1
# revision_id: andrew.bennetts at canonical.com-20070717065701-\
#   uq95aym0vtp7xykb
# target_branch: http://bazaar-vcs.org/bzr/bzr.dev
# testament_sha1: 60d20dbec5c2689feeba0557584c37478a4bcf65
# timestamp: 2007-07-17 16:57:26 +1000
# source_branch: http://people.ubuntu.com/~andrew/bzr/smart-server-\
#   logging
# 
# Bazaar revision bundle v0.9
#
# message:
#   Log errors from the smart server in the trace file, to make debugging test failures (and live failures!) easier.
# committer: Andrew Bennetts <andrew.bennetts at canonical.com>
# date: Tue 2007-07-17 16:57:01.654000044 +1000

=== modified file bzrlib/smart/protocol.py
--- bzrlib/smart/protocol.py
+++ bzrlib/smart/protocol.py
@@ -24,7 +24,7 @@
 from bzrlib import debug
 from bzrlib import errors
 from bzrlib.smart import request
-from bzrlib.trace import mutter
+from bzrlib.trace import log_exception_quietly, mutter
 
 
 # Protocol version strings.  These are sent as prefixes of bzr requests and
@@ -110,6 +110,7 @@
                 raise
             except Exception, exception:
                 # everything else: pass to client, flush, and quit
+                log_exception_quietly()
                 self._send_response(request.FailedSmartServerResponse(
                     ('error', str(exception))))
                 return

=== modified file bzrlib/tests/test_smart.py
--- bzrlib/tests/test_smart.py
+++ bzrlib/tests/test_smart.py
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-"""Tests for the smart wire/domain protococl."""
+"""Tests for the smart wire/domain protocol."""
 
 from StringIO import StringIO
 import tempfile

=== modified file bzrlib/tests/test_smart_transport.py
--- bzrlib/tests/test_smart_transport.py
+++ bzrlib/tests/test_smart_transport.py
@@ -1300,7 +1300,20 @@
         self.assertEqual(expected_tuple, smart_protocol.read_response_tuple())
 
 
-class TestSmartProtocolOne(TestSmartProtocol):
+class CommonSmartProtocolTestMixin(object):
+
+    def test_errors_are_logged(self):
+        """If an error occurs during testing, it is logged to the test log."""
+        out_stream = StringIO()
+        smart_protocol = self.server_protocol_class(None, out_stream.write)
+        # This triggers a "bad request" error.
+        smart_protocol.accept_bytes('abc\n')
+        test_log = self._get_log(keep_log_file=True)
+        self.assertContainsRe(test_log, 'Traceback')
+        self.assertContainsRe(test_log, 'SmartProtocolError')
+
+
+class TestSmartProtocolOne(TestSmartProtocol, CommonSmartProtocolTestMixin):
     """Tests for the smart protocol version one."""
 
     client_protocol_class = protocol.SmartClientRequestProtocolOne
@@ -1521,7 +1534,7 @@
             errors.ReadingCompleted, smart_protocol.read_body_bytes)
 
 
-class TestSmartProtocolTwo(TestSmartProtocol):
+class TestSmartProtocolTwo(TestSmartProtocol, CommonSmartProtocolTestMixin):
     """Tests for the smart protocol version two.
 
     This test case is mostly the same as TestSmartProtocolOne.

=== modified directory  // last-changed:andrew.bennetts at canonical.com-200707170
... 65701-uq95aym0vtp7xykb
# revision id: andrew.bennetts at canonical.com-20070717065701-uq95aym0vtp7xykb
# sha1: 60d20dbec5c2689feeba0557584c37478a4bcf65
# inventory sha1: 9d76d0fbc68f9d4cb6ce4fa9d0bab5df5b872ec2
# parent ids:
#   pqm at pqm.ubuntu.com-20070716205413-42lqws7bkld2gbju
# base id: pqm at pqm.ubuntu.com-20070716205413-42lqws7bkld2gbju
# properties:
#   branch-nick: smart-server-logging



More information about the bazaar mailing list