Skip to content

Commit

Permalink
feat(loader): Added hints for some serial port issues when rising por…
Browse files Browse the repository at this point in the history
…t error

Closes espressif/esp-idf#12366
  • Loading branch information
jakub-kocka committed Oct 11, 2023
1 parent ef02d52 commit d61da77
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions esptool/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,37 @@ def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD, trace_enabled=False):
try:
self._port = serial.serial_for_url(port)
except serial.serialutil.SerialException as e:
port_issues = [
[ # does not exist error
re.compile(r"Errno 2|FileNotFoundError", re.IGNORECASE),
"Check if the port is correct and ESP connected",
],
[ # busy port error
re.compile(r"Access is denied", re.IGNORECASE),
"Check if the port is not used by another task",
],
]
if sys.platform.startswith("linux"):
port_issues.append(
[ # permission denied error
re.compile(r"Permission denied", re.IGNORECASE),
(
"Try to add user into dialout group: "
"sudo usermod -a -G dialout $USER"
),
],
)

hint_msg = ""
for port_issue in port_issues:
if port_issue[0].search(str(e)):
hint_msg = f"\nHint: {port_issue[1]}\n"
break

raise FatalError(
f"Could not open {port}, the port is busy or doesn't exist."
f"\n({e})\n"
f"{hint_msg}"
)
else:
self._port = port
Expand Down

0 comments on commit d61da77

Please sign in to comment.