Genuine MicroPython croaks when accessing sys.exc_info()

Introduction

The pyboard-D on our workbench [1] got shipped with MicroPython v1.10.

MicroPython v1.10-445-ga9b1d3ca3 on 2019-05-29; PYBD_SF2W with STM32F722IEK

Using this, MicroPython croaks on code like

try:
    # Something fishy.
    pass
except:
    log.exception('Shutting down LTE modem failed')

with this message:

AttributeError: 'module' object has no attribute 'exc_info'

Bummer!


  1. Thanks, @Basti! ↩︎

The latest MicroPython firmware for the PYBD_SF2W is available from

Enable DFU bootloader mode

For the pyboard D-series you must enter the mboot DFU bootloader by holding down the USR button, pressing and releasing the RST button, and continuing to hold down USR until the LED is white (4th in the cycle), then let go of USR while the LED is white. The LED will then flash red once per second to indicate it is in USB DFU mode. You can then program the firmware using a DFU programmer, eg dfu-util or pydfu.py.

MicroPython - Python for microcontrollers

Program firmware

dfu-util --list

Found DFU: [0483:df11] ver=2200, devnum=7, cfg=1, intf=0, path="20-1", alt=0, name="@Internal Flash  /0x08000000/04*016Kg,01*064Kg,07*128Kg/0x80000000/64*32Kg/0x90000000/64*32Kg", serial="355931523037"
# Get current firmware from device.
dfu-util --serial="355931523037" --upload PYBD-SF2-v1.10-original.bin
# Write firmware into device.
wget http://micropython.org/resources/firmware/PYBD-SF2-20190915-v1.11-312-g22099ab88.dfu
dfu-util --serial="355931523037" --download PYBD-SF2-20190915-v1.11-312-g22099ab88.dfu
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Match vendor ID from file: 0483
Match product ID from file: df11
Deducing device DFU version from functional descriptor length
Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash  "
file contains 1 DFU images
parsing DFU image 1
image for alternate setting 0, (2 elements, total size = 901712)
parsing element 1, address = 0x08008000, size = 411088
Download	[=========================] 100%       411088 bytes
Download done.
parsing element 2, address = 0x90000000, size = 490608
Download	[=========================] 100%       490608 bytes
Download done.
done parsing DfuSe file

Unfortunately, the error is the same with the current firmware bringing in MicroPython v1.11.

offgrid:hiveeyes-micropython-firmware amo$ make console

Device port: usb => /dev/cu.usbmodem1412
Connecting via serial port /dev/cu.usbmodem1412.
.venv3/bin/miniterm.py /dev/cu.usbmodem1412 115200

--- Miniterm on /dev/cu.usbmodem1412  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
   1.2890 [terkin.device            ] INFO   : Turning off LTE modem

Traceback (most recent call last):
  File "main.py", line 43, in <module>
  File "main.py", line 38, in main
  File "datalogger.py", line 119, in start
  File "device.py", line 287, in power_off_lte_modem
  File "logging/__init__.py", line 72, in exception
AttributeError: 'module' object has no attribute 'exc_info'
MicroPython v1.11-312-g22099ab88 on 2019-09-15; PYBD-SF2W with STM32F722IEK

Looking for corresponding code fragments

indicate this might actually have worked the other day.

However, even with an updated

MicroPython v1.11-312-g22099ab88 on 2019-09-15; PYBD-SF2W with STM32F722IEK

this yields:

>>> import sys
>>> sys.exc_info()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'exc_info'

gives some more clues. We have been using the native code emitter.

Just made an Eingabe at Upstream as I would not know how to help myself further.

We got some valuable information from the MicroPython core developers and finally closed the issue at upstream [1].

sys.exc_info() is not enabled by default on MicroPython as it is not 100% compatible with the CPython version.

Following that discussion, we will adapt the MicroPython code to a different error handling pattern by propagating the exception object into log.exc(ex) instead of using the log.exception() method which gets the exception object by invoking sys.exc_info().


  1. Availability of sys.exc_info() in current builds · Issue #5110 · micropython/micropython · GitHub ↩︎

1 Like