bpo-41468: Improve and test IDLE run error exit (GH-21798)

A message box pops up when an unexpected error stops the run process.  Tell users it is likely a random glitch, but report it if not.
This commit is contained in:
Terry Jan Reedy 2020-08-09 16:08:30 -04:00 committed by GitHub
parent 8b67bf907c
commit f2e161c279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 10 deletions

View File

@ -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 bpo-41373: Save files loaded with no line ending, as when blank, or
different line endings, by setting its line ending to the system different line endings, by setting its line ending to the system
default. Fix regression in 3.8.4 and 3.9.0b4. default. Fix regression in 3.8.4 and 3.9.0b4.

View File

@ -1,9 +1,10 @@
"Test run, coverage 42%." "Test run, coverage 49%."
from idlelib import run from idlelib import run
import unittest import unittest
from unittest import mock 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 io
import sys import sys
@ -323,5 +324,32 @@ class RecursionLimitTest(unittest.TestCase):
self.assertEqual(func.__doc__, "more") 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__': if __name__ == '__main__':
unittest.main(verbosity=2) unittest.main(verbosity=2)

View File

@ -387,14 +387,21 @@ class MyRPCServer(rpc.RPCServer):
thread.interrupt_main() thread.interrupt_main()
except: except:
erf = sys.__stderr__ erf = sys.__stderr__
print('\n' + '-'*40, file=erf) print(textwrap.dedent(f"""
print('Unhandled server exception!', file=erf) {'-'*40}
print('Thread: %s' % threading.current_thread().name, file=erf) Unhandled exception in user code execution server!'
print('Client Address: ', client_address, file=erf) Thread: {threading.current_thread().name}
print('Request: ', repr(request), file=erf) IDLE Client Address: {client_address}
traceback.print_exc(file=erf) Request: {request!r}
print('\n*** Unrecoverable, server exiting!', file=erf) """), file=erf)
print('-'*40, 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 quitting = True
thread.interrupt_main() thread.interrupt_main()

View File

@ -0,0 +1 @@
Improve IDLE run crash error message (which users should never see).