Skip to content

unicode exception when using %run with failing script #1688

@jstenar

Description

@jstenar

When I %run the script below in a path containing non-ascii characters the traceback of a failing script is clobbered by a UnicodeDecodeError in IPython code.

import pdb
def a():
    a=1+2
    1/0
    b=2+4

a()

Correct behaviour when running in ascii path

In [1]: %run err.py
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
C:\python\ipydevel\VENV\Py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
    166             else:
    167                 filename = fname
--> 168             exec compile(scripttext, filename, 'exec') in glob, loc
    169     else:
    170         def execfile(fname, *where):

C:\python\ipydevel\err.py in <module>()
      5     b=2+4
      6
----> 7 a()

C:\python\ipydevel\err.py in a()
      2 def a():
      3     a=1+2
----> 4     1/0
      5     b=2+4
      6

ZeroDivisionError: integer division or modulo by zero

incorrect behaviour when running in non-ascii path

In [4]: %run err.py
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
C:\python\ipydevel\VENV\Py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\core\interactiveshell.pyc in run_code(self, code_obj)
   2623             self.CustomTB(etype,value,tb)
   2624         except:
-> 2625             self.showtraceback()
   2626         else:
   2627             outflag = 0

C:\python\ipydevel\VENV\Py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\core\interactiveshell.pyc in showtraceback(self, exc_tuple, filename, tb_offset, exception_only)
   1699                     else:
   1700                         stb = self.InteractiveTB.structured_traceback(etype,
-> 1701                                                 value, tb, tb_offset=tb_offset)
   1702
   1703                         self._showtraceback(etype, value, stb)

C:\python\ipydevel\VENV\Py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\core\ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, context)
   1163         self.tb = tb
   1164         return FormattedTB.structured_traceback(
-> 1165             self, etype, value, tb, tb_offset, context)
   1166
   1167 #---------------------------------------------------------------------------

C:\python\ipydevel\VENV\Py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\core\ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, context)
   1071             # Verbose modes need a full traceback
   1072             return VerboseTB.structured_traceback(
-> 1073                 self, etype, value, tb, tb_offset, context
   1074             )
   1075         else:

C:\python\ipydevel\VENV\Py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\core\ultratb.pyc in structured_traceback(self, etype, evalue, etb, tb_offset, context)
    917                 frames.append('%s%s' % (level,''.join(
    918                     _format_traceback_lines(lnum,index,lines,Colors,lvals,
--> 919                                             col_scheme))))
    920
    921         # Get (safely) a string form of the exception info

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 26: ordinal not in range(128)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions