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

Proposed by Maximiliano Bertacchini on 2018-06-25
Status: Merged
Merged at revision: 18693
Proposed branch: lp:~maxiberta/launchpad/sshkeyadditionerror-msg-format2
Merge into: lp:launchpad
Diff against target: 46 lines (+4/-4)
3 files modified
lib/lp/registry/interfaces/ssh.py (+2/-1)
lib/lp/registry/tests/test_ssh.py (+1/-1)
lib/lp/testing/__init__.py (+1/-2)
To merge this branch: bzr merge lp:~maxiberta/launchpad/sshkeyadditionerror-msg-format2
Reviewer Review Type Date Requested Status
Colin Watson 2018-06-25 Approve on 2018-06-25
Review via email: mp+348473@code.launchpad.net

Commit message

Fix encoding error message when handling SSHKeyAdditionError.

Description of the change

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)

To post a comment you must log in.
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/interfaces/ssh.py'
2--- lib/lp/registry/interfaces/ssh.py 2018-06-20 14:44:48 +0000
3+++ lib/lp/registry/interfaces/ssh.py 2018-06-25 15:51:23 +0000
4@@ -146,6 +146,7 @@
5 except UnicodeDecodeError:
6 # On Python 2, Key.fromString can raise exceptions with
7 # non-UTF-8 messages.
8- exception_text = bytes(exception).decode('unicode_escape')
9+ exception_text = bytes(exception).decode(
10+ 'unicode_escape').encode('unicode_escape')
11 msg = "%s (%s)" % (msg, exception_text)
12 super(SSHKeyAdditionError, self).__init__(msg, *args, **kwargs)
13
14=== modified file 'lib/lp/registry/tests/test_ssh.py'
15--- lib/lp/registry/tests/test_ssh.py 2018-06-20 14:44:48 +0000
16+++ lib/lp/registry/tests/test_ssh.py 2018-06-25 15:51:23 +0000
17@@ -173,7 +173,7 @@
18 self.assertRaisesWithContent(
19 SSHKeyAdditionError,
20 "Invalid SSH key data: 'ssh-rsa asdfasdf comment' "
21- u"(unknown blob type: \xc7_)",
22+ "(unknown blob type: \\xc7_)",
23 keyset.new,
24 person, 'ssh-rsa asdfasdf comment'
25 )
26
27=== modified file 'lib/lp/testing/__init__.py'
28--- lib/lp/testing/__init__.py 2018-06-25 09:16:49 +0000
29+++ lib/lp/testing/__init__.py 2018-06-25 15:51:23 +0000
30@@ -95,7 +95,6 @@
31 import pytz
32 import scandir
33 import simplejson
34-import six
35 from storm.store import Store
36 import subunit
37 import testtools
38@@ -652,7 +651,7 @@
39 match what was raised an AssertionError is raised.
40 """
41 err = self.assertRaises(exception, func, *args, **kwargs)
42- self.assertEqual(exception_content, six.text_type(err))
43+ self.assertEqual(exception_content, str(err))
44
45 def assertBetween(self, lower_bound, variable, upper_bound):
46 """Assert that 'variable' is strictly between two boundaries."""