[patch] add -Derror global option
Martin Pool
mbp at canonical.com
Tue Oct 31 06:30:52 GMT 2006
This patch
* Accepts -Danything as a global option, and stores them into a set of
debugging flags. (The specific values are not validated, for code
simplicity and so that they can be examined by plugins without
needing to get into registration etc; anyhow this is intended for
people who know what they're doing.)
* With -Derror a traceback is printed on all errors, even if bzr
thinks it's not an internal error. This is useful because we're
sometimes wrong.
--
Martin
-------------- next part --------------
=== added file 'bzrlib/tests/blackbox/test_debug.py'
--- bzrlib/tests/blackbox/test_debug.py 1970-01-01 00:00:00 +0000
+++ bzrlib/tests/blackbox/test_debug.py 2006-10-26 14:28:47 +0000
@@ -0,0 +1,32 @@
+# Copyright (C) 2006 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Blackbox tests for -D debug options"""
+
+import os
+
+from bzrlib.tests import TestCase
+
+class TestDebugOption(TestCase):
+
+ def test_dash_derror(self):
+ """With -Derror, tracebacks are shown even for user errors"""
+ out, err = self.run_bzr("-Derror", "branch", "nonexistent-location",
+ retcode=3)
+ # error output should contain a traceback
+ self.assertContainsRe(err, " raise errors\.NotBranchError")
+
+
=== modified file 'NEWS'
--- NEWS 2006-10-24 14:12:53 +0000
+++ NEWS 2006-10-26 14:24:35 +0000
@@ -4,6 +4,10 @@
INTERNALS:
+ * New -D option given before the command line turns on debugging output
+ for particular areas. -Derror shows tracebacks on all errors.
+ (Martin Pool)
+
BUG FIXES:
=== modified file 'bzrlib/__init__.py'
--- bzrlib/__init__.py 2006-10-24 14:12:53 +0000
+++ bzrlib/__init__.py 2006-10-26 14:20:31 +0000
@@ -54,6 +54,9 @@
'Consider using bzrlib.ignores.add_unique_user_ignores'
' or bzrlib.ignores.add_runtime_ignores')
+# Set of values that can enable printing particular debug messages
+debug_flags = set()
+
def test_suite():
import tests
return tests.test_suite()
=== modified file 'bzrlib/commands.py'
--- bzrlib/commands.py 2006-10-16 01:25:46 +0000
+++ bzrlib/commands.py 2006-10-26 14:21:18 +0000
@@ -533,6 +533,8 @@
opt_builtin = True
elif a in ('--quiet', '-q'):
trace.be_quiet()
+ elif a.startswith('-D'):
+ bzrlib.debug_flags.add(a[2:])
else:
argv_copy.append(a)
i += 1
=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- bzrlib/tests/blackbox/__init__.py 2006-10-11 23:08:27 +0000
+++ bzrlib/tests/blackbox/__init__.py 2006-10-26 14:12:19 +0000
@@ -51,6 +51,7 @@
'bzrlib.tests.blackbox.test_command_encoding',
'bzrlib.tests.blackbox.test_commit',
'bzrlib.tests.blackbox.test_conflicts',
+ 'bzrlib.tests.blackbox.test_debug',
'bzrlib.tests.blackbox.test_diff',
'bzrlib.tests.blackbox.test_exceptions',
'bzrlib.tests.blackbox.test_export',
=== modified file 'bzrlib/trace.py'
--- bzrlib/trace.py 2006-10-16 01:25:46 +0000
+++ bzrlib/trace.py 2006-10-26 14:27:36 +0000
@@ -281,6 +281,13 @@
# TODO: Should these be specially encoding the output?
def report_user_error(exc_info, err_file):
+ """Report to err_file an error that's not an internal error.
+
+ These don't get a traceback unless -Derror was given.
+ """
+ if 'error' in bzrlib.debug_flags:
+ report_bug(exc_info, err_file)
+ return
print >>err_file, "bzr: ERROR:", str(exc_info[1])
More information about the bazaar
mailing list