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

Important fatal errors should print to stderr (ESPTOOL-863) #981

Open
egnor opened this issue May 26, 2024 · 1 comment
Open

Important fatal errors should print to stderr (ESPTOOL-863) #981

egnor opened this issue May 26, 2024 · 1 comment

Comments

@egnor
Copy link

egnor commented May 26, 2024

Operating System

(relevant to most)

Esptool Version

4.7 (applicable to all)

Python Version

3.12.3 (applicable to all)

Full Esptool Command Line that Was Run

No response

Esptool Output

when pyserial is not installed, you see on STDERR (if stdout is filtered):

Traceback (most recent call last):
  File "/home/egnor/source/gadget_play/pintest/build/arduino/internal/esp32_esptool_py_4.5.1_7c51dd92fc1b703e/esptool.py", line 31, in <module>
    import esptool
  File "/home/egnor/source/gadget_play/pintest/build/arduino/internal/esp32_esptool_py_4.5.1_7c51dd92fc1b703e/esptool/__init__.py", line 41, in <module>
    from esptool.cmds import (
  File "/home/egnor/source/gadget_play/pintest/build/arduino/internal/esp32_esptool_py_4.5.1_7c51dd92fc1b703e/esptool/cmds.py", line 14, in <module>
    from .bin_image import ELFFile, ImageSegment, LoadFirmwareImage
  File "/home/egnor/source/gadget_play/pintest/build/arduino/internal/esp32_esptool_py_4.5.1_7c51dd92fc1b703e/esptool/bin_image.py", line 14, in <module>
    from .loader import ESPLoader
  File "/home/egnor/source/gadget_play/pintest/build/arduino/internal/esp32_esptool_py_4.5.1_7c51dd92fc1b703e/esptool/loader.py", line 30, in <module>
    import serial
ModuleNotFoundError: No module named 'serial'

What is the Expected Behaviour?

esptool should print the more-helpful error message on STDERR (which currently only goes to STDOUT):

Pyserial is not installed for [python binary]. Check the README for installation instructions.

More Information

Some fatal errors also print important messages the user should see

"Pyserial is not installed for %s. "

However, these print() to stdout, and in many cases (e.g. arduino-cli), esptool is run with stdout suppressed, so all you see is the native Python stack trace error.

Probably instead of print() and raise, these should raise an error with the error message, the way this does:

raise ImportError(

Other Steps to Reproduce

No response

@github-actions github-actions bot changed the title Important fatal errors should print to stderr Important fatal errors should print to stderr (ESPTOOL-863) May 26, 2024
@radimkarnis
Copy link
Collaborator

Hello @egnor,
thank you for the suggestion!

We are already tracking the request to send error messages to stderr (see e.g. #888). It will be implemented as a part of the next major release (v5.0) since it is a breaking change for current scripts relying on reading the stdout output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants