Skip to content
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

Issue2056 - Prevent tracebacks from accumulating in REPL #3702

Merged
merged 2 commits into from
Nov 16, 2020
Merged

Issue2056 - Prevent tracebacks from accumulating in REPL #3702

merged 2 commits into from
Nov 16, 2020

Conversation

DavePutz
Copy link
Collaborator

A minor bug fix for issue micropython#2056. Clear the exception traceback after printing in REPL.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @DavePutz!

@tannewt
Copy link
Member

tannewt commented Nov 16, 2020

Build failure was a network issue.

@tannewt tannewt merged commit 516a85a into adafruit:main Nov 16, 2020
@cwalther
Copy link

This is wrong. It prevents printing an exception twice, which I do in #3696 (once to measure the length of the traceback, once to get the text) and which people may want to do for other reasons, it’s available from Python via sys.print_exception(). (For some reason, it also causes the terminalio screen to be drawn over the stage screen, haven’t investigated that yet.)

The problem observed in micropython#2056 is specific to adafruit_midi in that it raises the same exception instance every time, a usage that apparently wasn’t anticipated in the core. Will have to dig deeper into how exceptions work to figure out how to properly fix that. It may be nontrivial – there would need to be a way to distinguish an exception reused in the way adafruit_midi does it from one re-raised in an except block.

In fact, I’m not sure it should be fixed, since CPython appears to do the same:

Python 3.8.3 (default, Jul  8 2020, 14:25:02) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> e = ValueError('X')
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    <?xml version="1.0" encoding="UTF-8"?>
ValueError: X
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    <?xml version="1.0" encoding="UTF-8"?>
  File "<stdin>", line 1, in <module>
    <?xml version="1.0" encoding="UTF-8"?>
ValueError: X
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    <?xml version="1.0" encoding="UTF-8"?>
  File "<stdin>", line 1, in <module>
    <?xml version="1.0" encoding="UTF-8"?>
  File "<stdin>", line 1, in <module>
    <?xml version="1.0" encoding="UTF-8"?>
ValueError: X

So maybe the proper fix is rather to make adafruit_midi stop reusing exceptions.

jepler added a commit that referenced this pull request Dec 15, 2020
#3702 breaks printing an exception twice
@DavePutz DavePutz deleted the issue2056 branch December 30, 2020 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants