Skip to content

bpo-41468: Improve and test IDLE run error exit #21798

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

Merged
merged 4 commits into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/idlelib/NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Released on 2020-10-05?
======================================


bpo-41468: Improve IDLE run crash error message (which users should
never see).

bpo-41373: Save files loaded with no line ending, as when blank, or
different line endings, by setting its line ending to the system
default. Fix regression in 3.8.4 and 3.9.0b4.
Expand Down
32 changes: 30 additions & 2 deletions Lib/idlelib/idle_test/test_run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"Test run, coverage 42%."
"Test run, coverage 49%."

from idlelib import run
import unittest
from unittest import mock
from test.support import captured_stderr
from idlelib.idle_test.mock_idle import Func
from test.support import captured_output, captured_stderr

import io
import sys
Expand Down Expand Up @@ -323,5 +324,32 @@ def func(): "docstring"
self.assertEqual(func.__doc__, "more")


class HandleErrorTest(unittest.TestCase):
# Method of MyRPCServer
func = Func()
@mock.patch('idlelib.run.thread.interrupt_main', new=func)
def test_error(self):
eq = self.assertEqual
with captured_output('__stderr__') as err:
try:
raise EOFError
except EOFError:
run.MyRPCServer.handle_error(None, 'abc', '123')
eq(run.exit_now, True)
run.exit_now = False
eq(err.getvalue(), '')

try:
raise IndexError
except IndexError:
run.MyRPCServer.handle_error(None, 'abc', '123')
eq(run.quitting, True)
run.quitting = False
msg = err.getvalue()
self.assertIn('abc', msg)
self.assertIn('123', msg)
self.assertIn('IndexError', msg)
eq(self.func.called, 2)

if __name__ == '__main__':
unittest.main(verbosity=2)
23 changes: 15 additions & 8 deletions Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,21 @@ def handle_error(self, request, client_address):
thread.interrupt_main()
except:
erf = sys.__stderr__
print('\n' + '-'*40, file=erf)
print('Unhandled server exception!', file=erf)
print('Thread: %s' % threading.current_thread().name, file=erf)
print('Client Address: ', client_address, file=erf)
print('Request: ', repr(request), file=erf)
traceback.print_exc(file=erf)
print('\n*** Unrecoverable, server exiting!', file=erf)
print('-'*40, file=erf)
print(textwrap.dedent(f"""
{'-'*40}
Unhandled exception in user code execution server!'
Thread: {threading.current_thread().name}
IDLE Client Address: {client_address}
Request: {request!r}
"""), file=erf)
traceback.print_exc(limit=-20, file=erf)
print(textwrap.dedent(f"""
*** Unrecoverable, server exiting!

Users should never see this message; it is likely transient.
If this recurs, report this with a copy of the message
and an explanation of how to make it repeat.
{'-'*40}"""), file=erf)
quitting = True
thread.interrupt_main()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve IDLE run crash error message (which users should never see).