[PATCH 3 of 7] blackbox: make blackbox not abort if it cannot read

timeless timeless at mozdev.org
Wed Feb 3 16:40:45 EST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1454522670 0
#      Wed Feb 03 18:04:30 2016 +0000
# Node ID 552c58b545c24037fcf09d4ca39c65628bd1c654
# Parent  53190dfbd7ebb3fe6bc714ce08f8c1a7ae7ef16e
blackbox: make blackbox not abort if it cannot read

The test claimed it was "fine", but the output was an abort.
This changes the output to match the behavior described by
the test instead of the output the test showed...

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -143,13 +143,16 @@
     '''view the recent repository events
     '''
 
-    if not os.path.exists(repo.join('blackbox.log')):
+    limit = opts.get('limit')
+    try:
+        blackbox = repo.vfs('blackbox.log', 'r')
+        lines = blackbox.read().split('\n')
+    except (IOError, OSError) as err:
+        ui.warn(_("could not open blackbox log file\n"))
+        ui.debug('warning: could not open blackbox.log: %s\n' %
+                 err.strerror)
         return
 
-    limit = opts.get('limit')
-    blackbox = repo.vfs('blackbox.log', 'r')
-    lines = blackbox.read().split('\n')
-
     count = 0
     output = []
     for line in reversed(lines):
diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -89,9 +89,11 @@
 a failure reading from the log is fine
 
   $ hg blackbox -l 3
-  abort: *: $TESTTMP/blackboxtest2/.hg/blackbox.log (glob)
-  [255]
-
+  could not open blackbox log file
+  $ hg blackbox --debug
+  warning: cannot write to blackbox.log: * (glob)
+  could not open blackbox log file
+  warning: could not open blackbox.log: * (glob)
   $ rmdir .hg/blackbox.log
   $ mv .hg/blackbox.log- .hg/blackbox.log
 


More information about the Mercurial-devel mailing list