Rev 3501: (mbp) better messages about missing libraries in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Jun 18 03:16:01 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3501
revision-id:pqm at pqm.ubuntu.com-20080618021553-nptumo40ezmv5ksr
parent: pqm at pqm.ubuntu.com-20080618014427-zxkz0qy5140z7b32
parent: mbp at sourcefrog.net-20080617012947-qwi4yxfadjtiozk1
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-06-18 03:15:53 +0100
message:
  (mbp) better messages about missing libraries
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzr                            bzr.py-20050313053754-5485f144c7006fa6
  bzrlib/tests/test_trace.py     testtrace.py-20051110225523-a21117fc7a07eeff
  bzrlib/trace.py                trace.py-20050309040759-c8ed824bdcd4748a
  doc/developers/releasing.txt   releasing.txt-20080502015919-fnrcav8fwy8ccibu-1
    ------------------------------------------------------------
    revno: 3497.3.3
    revision-id:mbp at sourcefrog.net-20080617012947-qwi4yxfadjtiozk1
    parent: mbp at sourcefrog.net-20080617011349-jsqy1id9wgk2pqzs
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: trivial
    timestamp: Tue 2008-06-17 11:29:47 +1000
    message:
      Clearer message about how to set PYTHONPATH
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzr                            bzr.py-20050313053754-5485f144c7006fa6
    ------------------------------------------------------------
    revno: 3497.3.2
    revision-id:mbp at sourcefrog.net-20080617011349-jsqy1id9wgk2pqzs
    parent: mbp at sourcefrog.net-20080617001839-6nteey06saa9b2k3
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: trivial
    timestamp: Tue 2008-06-17 11:13:49 +1000
    message:
      Show short error for missing libraries
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/test_trace.py     testtrace.py-20051110225523-a21117fc7a07eeff
      bzrlib/trace.py                trace.py-20050309040759-c8ed824bdcd4748a
    ------------------------------------------------------------
    revno: 3497.3.1
    revision-id:mbp at sourcefrog.net-20080617001839-6nteey06saa9b2k3
    parent: pqm at pqm.ubuntu.com-20080616174225-2eokonl40p9ogzbw
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: trivial
    timestamp: Tue 2008-06-17 10:18:39 +1000
    message:
      Add note to update GNU directory
    modified:
      doc/developers/releasing.txt   releasing.txt-20080502015919-fnrcav8fwy8ccibu-1
=== modified file 'NEWS'
--- a/NEWS	2008-06-18 01:44:27 +0000
+++ b/NEWS	2008-06-18 02:15:53 +0000
@@ -16,6 +16,15 @@
 
   BUGFIXES:
 
+    * Clearer message about how to set the PYTHONPATH if bzrlib can't be
+      loaded. 
+      (Martin Pool, #205230)
+
+    * Errors about missing libraries are now shown without a traceback,
+      and with a suggestion to install the library.  The full traceback is 
+      still in ``.bzr.log`` and can be shown with ``-Derror``.
+      (Martin Pool, #240161)
+
     * ``needs_read_lock`` and ``needs_write_lock`` now suppress an error during
       ``unlock`` if there was an error in the original function. This helps
       most when there is a failure with a smart server action, since often the

=== modified file 'bzr'
--- a/bzr	2008-05-10 11:33:32 +0000
+++ b/bzr	2008-06-17 01:29:47 +0000
@@ -64,9 +64,9 @@
     import bzrlib
 except ImportError, e:
     sys.stderr.write("bzr: ERROR: "
-                     "Couldn't import bzrlib and dependencies.\n"
-                     "Please check bzrlib is on your PYTHONPATH.\n"
-                     "\n")
+        "Couldn't import bzrlib and dependencies.\n"
+        "Please check the directory containing bzrlib is on your PYTHONPATH.\n"
+        "\n")
     raise
 
 if bzrlib.version_info[:3] != _script_version:

=== modified file 'bzrlib/tests/test_trace.py'
--- a/bzrlib/tests/test_trace.py	2008-02-07 03:49:57 +0000
+++ b/bzrlib/tests/test_trace.py	2008-06-17 01:13:49 +0000
@@ -93,6 +93,28 @@
         self.assertTrue(len(msg) > 0)
         self.assertEqualDiff(msg, 'bzr: ERROR: Not a branch: \"wibble\".\n')
 
+    def test_report_external_import_error(self):
+        """Short friendly message for missing system modules."""
+        try:
+            import ImaginaryModule
+        except ImportError, e:
+            pass
+        else:
+            self.fail("somehow succeeded in importing %r" % ImaginaryModule)
+        msg = _format_exception()
+        self.assertEqual(msg,
+            'bzr: ERROR: No module named ImaginaryModule\n'
+            'You may need to install this Python library separately.\n')
+
+    def test_report_import_syntax_error(self):
+        try:
+            raise ImportError("syntax error")
+        except ImportError, e:
+            pass
+        msg = _format_exception()
+        self.assertContainsRe(msg,
+            r"Traceback \(most recent call last\)")
+
     def test_trace_unicode(self):
         """Write Unicode to trace log"""
         self.log(u'the unicode character for benzene is \N{BENZENE RING}')

=== modified file 'bzrlib/trace.py'
--- a/bzrlib/trace.py	2008-05-15 17:24:12 +0000
+++ b/bzrlib/trace.py	2008-06-17 01:13:49 +0000
@@ -401,6 +401,11 @@
     elif isinstance(exc_object, KeyboardInterrupt):
         err_file.write("bzr: interrupted\n")
         return errors.EXIT_ERROR
+    elif isinstance(exc_object, ImportError) \
+        and str(exc_object).startswith("No module named "):
+        report_user_error(exc_info, err_file,
+            'You may need to install this Python library separately.')
+        return errors.EXIT_ERROR
     elif not getattr(exc_object, 'internal_error', True):
         report_user_error(exc_info, err_file)
         return errors.EXIT_ERROR
@@ -423,15 +428,21 @@
 
 
 # TODO: Should these be specially encoding the output?
-def report_user_error(exc_info, err_file):
+def report_user_error(exc_info, err_file, advice=None):
     """Report to err_file an error that's not an internal error.
 
     These don't get a traceback unless -Derror was given.
+
+    :param exc_info: 3-tuple from sys.exc_info()
+    :param advice: Extra advice to the user to be printed following the
+        exception.
     """
     if 'error' in debug.debug_flags:
         print_exception(exc_info, err_file)
         return
     err_file.write("bzr: ERROR: %s\n" % (exc_info[1],))
+    if advice:
+        err_file.write("%s\n" % (advice,))
 
 
 def report_bug(exc_info, err_file):

=== modified file 'doc/developers/releasing.txt'
--- a/doc/developers/releasing.txt	2008-06-11 02:28:10 +0000
+++ b/doc/developers/releasing.txt	2008-06-17 00:18:39 +0000
@@ -239,6 +239,8 @@
 #. For final releases, also send the announcement mail to
    info-gnu at gnu.org and python-announce-list at python.org.
 
+#. Also send a GNU directory update to bug-directory at gnu.org.
+
 #. Update the python package index: <http://pypi.python.org/pypi/bzr> - best
    done by running ::
 




More information about the bazaar-commits mailing list