-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shell restart when error message contains non-BMP characters #80879
Comments
When attempting to raise an error with a message containing non-BMP characters (Unicode ordinals above U+0xFFFF), the python shell displays a long traceback including several UnicodeEncodeErrors and then restarts. Example: >>> raise Exception('\U0001f603')
Traceback (most recent call last):
File "<pyshell#84>", line 1, in <module>
raise Exception('\U0001f603')
Traceback (most recent call last):
File "<pyshell#84>", line 1, in <module>
raise Exception('\U0001f603')
Traceback (most recent call last):
File "D:\Python37\lib\idlelib\run.py", line 474, in runcode
exec(code, self.locals)
File "<pyshell#84>", line 1, in <module>
Traceback (most recent call last):
File "D:\Python37\lib\idlelib\run.py", line 474, in runcode
exec(code, self.locals)
File "<pyshell#84>", line 1, in <module>
Exception:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python37\lib\idlelib\run.py", line 144, in main
ret = method(*args, **kwargs)
File "D:\Python37\lib\idlelib\run.py", line 486, in runcode
print_exception()
File "D:\Python37\lib\idlelib\run.py", line 234, in print_exception
print_exc(typ, val, tb)
File "D:\Python37\lib\idlelib\run.py", line 232, in print_exc
print(line, end='', file=efile)
File "D:\Python37\lib\idlelib\run.py", line 362, in write
return self.shell.write(s, self.tags)
File "D:\Python37\lib\idlelib\rpc.py", line 608, in __call__
value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
File "D:\Python37\lib\idlelib\rpc.py", line 220, in remotecall
return self.asyncreturn(seq)
File "D:\Python37\lib\idlelib\rpc.py", line 251, in asyncreturn
return self.decoderesponse(response)
File "D:\Python37\lib\idlelib\rpc.py", line 271, in decoderesponse
raise what
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 11-11: Non-BMP character not supported in Tk
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python37\lib\idlelib\run.py", line 158, in main
print_exception()
File "D:\Python37\lib\idlelib\run.py", line 234, in print_exception
print_exc(typ, val, tb)
File "D:\Python37\lib\idlelib\run.py", line 220, in print_exc
print_exc(type(context), context, context.__traceback__)
File "D:\Python37\lib\idlelib\run.py", line 232, in print_exc
print(line, end='', file=efile)
File "D:\Python37\lib\idlelib\run.py", line 362, in write
return self.shell.write(s, self.tags)
File "D:\Python37\lib\idlelib\rpc.py", line 608, in __call__
value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
File "D:\Python37\lib\idlelib\rpc.py", line 220, in remotecall
return self.asyncreturn(seq)
File "D:\Python37\lib\idlelib\rpc.py", line 251, in asyncreturn
return self.decoderesponse(response)
File "D:\Python37\lib\idlelib\rpc.py", line 271, in decoderesponse
raise what
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 11-11: Non-BMP character not supported in Tk
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\Python37\lib\idlelib\run.py", line 162, in main
traceback.print_exception(type, value, tb, file=sys.__stderr__)
File "D:\Python37\lib\traceback.py", line 105, in print_exception
print(line, file=file, end="")
File "D:\Python37\lib\idlelib\run.py", line 362, in write
return self.shell.write(s, self.tags)
File "D:\Python37\lib\idlelib\rpc.py", line 608, in __call__
value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
File "D:\Python37\lib\idlelib\rpc.py", line 220, in remotecall
return self.asyncreturn(seq)
File "D:\Python37\lib\idlelib\rpc.py", line 251, in asyncreturn
return self.decoderesponse(response)
File "D:\Python37\lib\idlelib\rpc.py", line 271, in decoderesponse
raise what
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 11-11: Non-BMP character not supported in Tk =============================== RESTART: Shell ===============================
I presume the error is caused by Tk being unable to display the characters in the error message, but being forced to anyway by the traceback, causing a series of UnicodeEncodeErrors. Perhaps the error handler should use repr() or similar methods to convert the message into a displayable form? |
You are correct about reason. This is essentially a duplicate of bpo-22742, but I am leaving it open for now because the behavior is worse and there is additional information in the tracebacks. The lines for IDLE internals are normally removed, but the exception during the exception prevented that. |
Mostly fixed by PR 16545 (see bpo-13153). The original example is now passed. >>> raise Exception('\U0001f603')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
raise Exception('\U0001f603')
Exception: 😃
>>> But you can still cause a restart of the shell by using surrogate characters: >>> raise Exception('\ud800')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
raise Exception('\ud800')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
raise Exception('\ud800') ================================ RESTART: Shell ================================
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: