[MERGE][Bug #116143] commit raises UnicodeError (traceback) if LANG is incorrect (attempt #3)

Martin Pool mbp at canonical.com
Tue Aug 7 07:39:54 BST 2007


Martin Pool has voted tweak.
Status is now: Conditionally approved
Comment:
=== modified file bzrlib/commands.py // 
last-changed:d.m.watkins at warwick.ac.uk-
... 20070727225945-y8qywyj9hsqrlvjc
--- bzrlib/commands.py
+++ bzrlib/commands.py
@@ -718,7 +718,11 @@
      import bzrlib.ui
      from bzrlib.ui.text import TextUIFactory
      bzrlib.ui.ui_factory = TextUIFactory()
-    argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
+    try:
+        argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
+    except UnicodeDecodeError:
+        raise errors.BzrError(("Parameter '%s' is unsupported by the 
current "
+                                                            "encoding." 
% a))
      ret = run_bzr_catch_errors(argv)
      trace.mutter("return code %d", ret)
      return ret

This seems to apply to not just commit but the arguments/options of all 
commands?  If so, the news file should say so.

Given that we know a is unrepresentable it seems a bit provocative(?) to 
print it with %s rather than %r.

+
+    def test_unsupported_encoding_commit_message(self):
+        old_env = osutils.set_or_unset_env('LANG', 'C')
+        self.make_fake_editor(message='\xff')
+
+        working_tree = self.make_uncommitted_tree()
+        self.assertRaises(errors.BadCommitMessageEncoding,
+ 
bzrlib.msgeditor.edit_commit_message, '')
+
+        osutils.set_or_unset_env('LANG', old_env)

The restoration should be in a finally block.

+                    lastline = nlines
+                msg.append(line)
+            f.close()
+        except UnicodeDecodeError:
+            f.close()
+            raise BadCommitMessageEncoding()

It would be cleaner to have, after the except block

   finally:
     f.close()

For details, see: 
http://bundlebuggy.aaronbentley.com/request/%3C46AE13E0.3000904%40warwick.ac.uk%3E



More information about the bazaar mailing list