Skip to content

Commit

Permalink
feat: print exceptions to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
Massimiliano-solutiontech committed Aug 24, 2023
1 parent 69201c3 commit 7a5ea44
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion espefuse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _main():
try:
main()
except esptool.FatalError as e:
print("\nA fatal error occurred: %s" % e)
print("\nA fatal error occurred: %s" % e, file=sys.stderr)
sys.exit(2)


Expand Down
3 changes: 2 additions & 1 deletion espsecure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ def _main():
try:
main()
except esptool.FatalError as e:
print("\nA fatal error occurred: %s" % e)
print("\nA fatal error occurred: %s" % e, file=sys.stderr)
sys.exit(2)
except ValueError as e:
try:
Expand All @@ -1819,6 +1819,7 @@ def _main():
"Note: This error originates from the cryptography module. "
"It is likely not a problem with espsecure, "
"please make sure you are using a compatible OpenSSL backend."
, file=sys.stderr
)
finally:
raise
Expand Down
10 changes: 6 additions & 4 deletions esptool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,23 +1072,25 @@ def _main():
try:
main()
except FatalError as e:
print(f"\nA fatal error occurred: {e}")
print(f"\nA fatal error occurred: {e}", file=sys.stderr)
sys.exit(2)
except serial.serialutil.SerialException as e:
print(f"\nA serial exception error occurred: {e}")
print(f"\nA serial exception error occurred: {e}", file=sys.stderr)
print(
"Note: This error originates from pySerial. "
"It is likely not a problem with esptool, "
"but with the hardware connection or drivers."
, file=sys.stderr
)
print(
"For troubleshooting steps visit: "
"https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html"
, file=sys.stderr
)
sys.exit(1)
except StopIteration:
print(traceback.format_exc())
print("A fatal error occurred: The chip stopped responding.")
print(traceback.format_exc(), file=sys.stderr)
print("A fatal error occurred: The chip stopped responding.", file=sys.stderr)
sys.exit(2)


Expand Down
2 changes: 1 addition & 1 deletion flasher_stub/esptool_test_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
try:
esptool.main()
except esptool.FatalError as e:
print("\nA fatal error occurred: %s" % e)
print("\nA fatal error occurred: %s" % e, file=sys.stderr)
sys.exit(2)

0 comments on commit 7a5ea44

Please sign in to comment.