This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unicode exceptions terminate pdb.pm() loop
Type: behavior Stage: test needed
Components: Library (Lib), Unicode Versions: Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, ezio.melotti, georg.brandl, mgedmin
Priority: normal Keywords: patch

Created on 2009-12-18 11:55 by mgedmin, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test-pdb-unicode-exc.diff mgedmin, 2009-12-21 01:17 patch adding a test
pdb-unicode-exc.patch amaury.forgeotdarc, 2009-12-29 13:02
Messages (4)
msg96560 - (view) Author: Marius Gedminas (mgedmin) * Date: 2009-12-18 11:55
$ python2.6
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> None()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
>>> import pdb; pdb.pm()
> <stdin>(1)<module>()
(Pdb) raise Exception(u'\xff')
*** Exception: Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/pdb.py", line 1239, in pm
    post_mortem(sys.last_traceback)
  File "/usr/lib/python2.6/pdb.py", line 1236, in post_mortem
    p.interaction(None, t)
  File "/usr/lib/python2.6/pdb.py", line 194, in interaction
    self.cmdloop()
  File "/usr/lib/python2.6/cmd.py", line 142, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib/python2.6/pdb.py", line 261, in onecmd
    return cmd.Cmd.onecmd(self, line)
  File "/usr/lib/python2.6/cmd.py", line 218, in onecmd
    return self.default(line)
  File "/usr/lib/python2.6/pdb.py", line 226, in default
    print >>self.stdout, '***', exc_type_name + ':', v
UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in 
position 0: ordinal not in range(128)
>>> 

Note that the post-mortem loop is terminated (if you do pdb.set_trace() 
instead of pdb.pm(), that doesn't happen).

This is rather irritating then you're trying to post-mortem debug a 
failed test with expensive setup, when leaving the postmortem pdb 
session exits the process.

Python 3.1 is not affected.  I don't have 2.7 handy.
msg96730 - (view) Author: Marius Gedminas (mgedmin) * Date: 2009-12-21 01:17
I don't know what I was smoking when I said pdb.set_trace() wasn't 
affected; I just reproduced the bug with 

Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb
>>> pdb.set_trace()
--Return--
> <stdin>(1)<module>()->None
(Pdb) raise Exception(u'\xff')
*** Exception: Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/bdb.py", line 50, in trace_dispatch
    return self.dispatch_return(frame, arg)
  File "/usr/lib/python2.6/bdb.py", line 83, in dispatch_return
    self.user_return(frame, arg)
  File "/usr/lib/python2.6/pdb.py", line 176, in user_return
    self.interaction(frame, None)
  File "/usr/lib/python2.6/pdb.py", line 194, in interaction
    self.cmdloop()
  File "/usr/lib/python2.6/cmd.py", line 142, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib/python2.6/pdb.py", line 261, in onecmd
    return cmd.Cmd.onecmd(self, line)
  File "/usr/lib/python2.6/cmd.py", line 218, in onecmd
    return self.default(line)
  File "/usr/lib/python2.6/pdb.py", line 226, in default
    print >>self.stdout, '***', exc_type_name + ':', v
UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in 
position 0: ordinal not in range(128)
>>> 

This makes testing simpler; attached is my very first patch for the 
Python test suite, please review it mercilessly.

(I verified that the test will pass once the bug is fixed by replacing 
U+00FF with U+0001 and seeing that it passes.)
msg96994 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-12-29 13:02
Here is a patch, along with the test that I modified a little bit:
- it uses _saferepr (and repr.Repr) to render the exception object
- it also fixes exception raised by the "p" action.
- The test uses a raw docstring, to avoid chr(255) in the string
msg112053 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-30 09:19
Thanks, applied to 2.7 branch in r83267.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51788
2010-07-30 09:19:24georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112053

resolution: fixed
2009-12-29 13:02:47amaury.forgeotdarcsetfiles: + pdb-unicode-exc.patch
nosy: + amaury.forgeotdarc
messages: + msg96994

2009-12-21 01:17:33mgedminsetfiles: + test-pdb-unicode-exc.diff
keywords: + patch
messages: + msg96730
2009-12-18 11:56:49ezio.melottisetpriority: normal
nosy: + ezio.melotti

stage: test needed
2009-12-18 11:55:38mgedmincreate