← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~maxiberta/launchpad/sshkeyadditionerror-msg-format2 into lp:launchpad

 

Maximiliano Bertacchini has proposed merging lp:~maxiberta/launchpad/sshkeyadditionerror-msg-format2 into lp:launchpad.

Commit message:
Fix encoding error message when handling SSHKeyAdditionError.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~maxiberta/launchpad/sshkeyadditionerror-msg-format2/+merge/348473

Further encode error message when handling SSHKeyAdditionError. Reverts unicode encoding in assertRaisesWithContent() back to `str(exception)` to make sure it won't crash in lazr's error handling code, as in e.g.:

  UnicodeEncodeError: 'ascii' codec can't encode character u'\xc7' in position 67: ordinal not in range(128)
    Traceback (most recent call last):
  Module zope.app.publication.zopepublication, line 379, in handleException
    body = mapply(view, (), request)
  Module zope.publisher.publish, line 107, in mapply
    return debug_call(obj, args)
   - __traceback_info__: <lazr.restful.error.WebServiceExceptionView object at 0x7fca857f5c10>
  Module zope.publisher.publish, line 113, in debug_call
    return obj(*args)
  Module lazr.restful.error, line 78, in __call__
    result = [str(self.context)]
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc7' in position 67: ordinal not in range(128)
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~maxiberta/launchpad/sshkeyadditionerror-msg-format2 into lp:launchpad.
=== modified file 'lib/lp/registry/interfaces/ssh.py'
--- lib/lp/registry/interfaces/ssh.py	2018-06-20 14:44:48 +0000
+++ lib/lp/registry/interfaces/ssh.py	2018-06-25 15:51:23 +0000
@@ -146,6 +146,7 @@
             except UnicodeDecodeError:
                 # On Python 2, Key.fromString can raise exceptions with
                 # non-UTF-8 messages.
-                exception_text = bytes(exception).decode('unicode_escape')
+                exception_text = bytes(exception).decode(
+                    'unicode_escape').encode('unicode_escape')
             msg = "%s (%s)" % (msg, exception_text)
         super(SSHKeyAdditionError, self).__init__(msg, *args, **kwargs)

=== modified file 'lib/lp/registry/tests/test_ssh.py'
--- lib/lp/registry/tests/test_ssh.py	2018-06-20 14:44:48 +0000
+++ lib/lp/registry/tests/test_ssh.py	2018-06-25 15:51:23 +0000
@@ -173,7 +173,7 @@
         self.assertRaisesWithContent(
             SSHKeyAdditionError,
             "Invalid SSH key data: 'ssh-rsa asdfasdf comment' "
-            u"(unknown blob type: \xc7_)",
+            "(unknown blob type: \\xc7_)",
             keyset.new,
             person, 'ssh-rsa asdfasdf comment'
         )

=== modified file 'lib/lp/testing/__init__.py'
--- lib/lp/testing/__init__.py	2018-06-25 09:16:49 +0000
+++ lib/lp/testing/__init__.py	2018-06-25 15:51:23 +0000
@@ -95,7 +95,6 @@
 import pytz
 import scandir
 import simplejson
-import six
 from storm.store import Store
 import subunit
 import testtools
@@ -652,7 +651,7 @@
         match what was raised an AssertionError is raised.
         """
         err = self.assertRaises(exception, func, *args, **kwargs)
-        self.assertEqual(exception_content, six.text_type(err))
+        self.assertEqual(exception_content, str(err))
 
     def assertBetween(self, lower_bound, variable, upper_bound):
         """Assert that 'variable' is strictly between two boundaries."""


Follow ups