circuitpython: Application exception output to serial (over USB) appears truncated due to buffering issue

My near-perfect code has just spat an exception. I’m running 4.0.0-beta.3-4-g186e31591-dirty which 4.0.0 beta 3 with a minor tweak. The exception has half-appeared on my console (PuTTY on Windows) from the CPX over USB:

Press any key to enter the REPL. Use CTRL-D to reload.soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Shared couter PWM failure I - trying in reverse order
Shared couter PWM failure II - soft/hard reset suggested
Ready to play
Traceback (most recent call last):
  File "code.py", line

There’s a single space after line - the absence of the rest of the text on the line makes it very apparent it’s truncated. When I press the enter key and the rest appears leaving it looking like this:

Press any key to enter the REPL. Use CTRL-D to reload.soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Shared couter PWM failure I - trying in reverse order
Shared couter PWM failure II - soft/hard reset suggested
Ready to play
Traceback (most recent call last):
  File "code.py", line 199, in <module>
TypeError: list indices must be integers, not tuple



Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 4.0.0-beta.3-4-g186e31591-dirty on 2019-03-11; Adafruit CircuitPlayground Express with samd21g18

I’ve never noticed that before and I use this setup a lot. It appears fully reproducible for this particular code/error combo. Are there differences in the way 4.0.0 vs previous versions writes to serial or how it reports exceptions?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 39 (14 by maintainers)

Most upvoted comments

Hi,

  The fix looks good to me. I ran 100 tests on a CircuitPlayground

Express with no errors. Thanks!

                      -Dave

On Fri, Apr 17, 2020 at 4:36 AM Ha Thach notifications@github.com wrote:

@kevinjwalters https://github.com/kevinjwalters can you download 2 file of cdc driver below replace (after removed the .txt) to lib/tinyusb/src/class/cdc . I tested here and it seems to be fine. Once confirmed I will make an PR to update tinyusb submodule. It may take a bit of time since there are ~500 commits comparing with current one used by cpy. Though we need to update anyway for the esp32-s2 support.

cdc_device.c.txt https://github.com/adafruit/circuitpython/files/4492065/cdc_device.c.txt cdc_device.h.txt https://github.com/adafruit/circuitpython/files/4492066/cdc_device.h.txt

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/adafruit/circuitpython/issues/1639#issuecomment-615147760, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNJKEWADN4XON2BZDYHDOTRNAPINANCNFSM4G5MW2QQ .

4.x uses a different USB stack than 3.x so it’s likely a bug in TinyUSB. Maybe @hathach will take a look.

@hathach I’m starting to look at ESP32-S2 today again and will likely do the TinyUSB update as part of that.

I could reproduce the issue with detail instruction from @DavePutz, will try to troubleshoot it and post update here.

This should return
 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError:
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij

When it fails it only returns
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError

The rest of the output only prints after you press any key.

If this only affects serial writes then I would say it’s not overly important to address quickly.

I find it easy to reproduce on REPL and if there’s a good way to debug a board where you can see what function is being used that would give away what’s going on. For REPL if you keep trying to reproduce it then the frequency of occurrence dramatically drops, it’s almost as if it goes into hiding!