[Pkg-bazaar-commits] ./bzr/unstable r317: - better error message for broken pipe

Martin Pool mbp at sourcefrog.net
Fri Apr 10 07:43:49 UTC 2009


------------------------------------------------------------
revno: 317
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-05-02 14:32:56 +1000
message:
  - better error message for broken pipe
modified:
  NEWS
  bzrlib/commands.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-04-29 00:49:59 +0000
+++ b/NEWS	2005-05-02 04:32:56 +0000
@@ -7,6 +7,9 @@
 
     * New 'bzr ignore PATTERN' command.
 
+    * Nicer error message for broken pipe and similar conditions that
+      don't indicate an internal error.
+
   TESTING:
 
     * Converted black-box test suites from Bourne shell into Python.

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-04-28 10:31:44 +0000
+++ b/bzrlib/commands.py	2005-05-02 04:32:56 +0000
@@ -1106,15 +1106,17 @@
 
 
 
-def _report_exception(e, summary):
+def _report_exception(e, summary, quiet=False):
     import traceback
     log_error('bzr: ' + summary)
     bzrlib.trace.log_exception(e)
-    tb = sys.exc_info()[2]
-    exinfo = traceback.extract_tb(tb)
-    if exinfo:
-        sys.stderr.write('  at %s:%d in %s()\n' % exinfo[-1][:3])
-    sys.stderr.write('  see ~/.bzr.log for debug information\n')
+
+    if not quiet:
+        tb = sys.exc_info()[2]
+        exinfo = traceback.extract_tb(tb)
+        if exinfo:
+            sys.stderr.write('  at %s:%d in %s()\n' % exinfo[-1][:3])
+        sys.stderr.write('  see ~/.bzr.log for debug information\n')
 
 
 def cmd_assert_fail():
@@ -1122,11 +1124,15 @@
 
 
 def main(argv):
+    import errno
+    
     bzrlib.trace.create_tracefile(argv)
 
     try:
         try:
             ret = run_bzr(argv)
+            # do this here to catch EPIPE
+            sys.stdout.flush()
             return ret
         except BzrError, e:
             _report_exception(e, 'error: ' + e.args[0])
@@ -1141,16 +1147,17 @@
                 msg += ': ' + str(e)
             _report_exception(e, msg)
         except Exception, e:
-            _report_exception(e, 'exception: %s' % str(e).rstrip('\n'))
+            quiet = False
+            if isinstance(e, IOError) and e.errno == errno.EPIPE:
+                quiet = True
+                msg = 'broken pipe'
+            else:
+                msg = str(e).rstrip('\n')
+            _report_exception(e, msg, quiet)
             return 1
     finally:
         bzrlib.trace.close_trace()
 
-    ## TODO: Trap AssertionError
-
-    # TODO: Maybe nicer handling of IOError especially for broken pipe.
-
-
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv))



More information about the Pkg-bazaar-commits mailing list