mirror of
https://github.com/espressif/esptool.git
synced 2025-10-17 16:01:18 +08:00
feat(loader): Added hints for some serial port issues when rising port error
Closes https://github.com/espressif/esp-idf/issues/12366
This commit is contained in:
@@ -302,9 +302,37 @@ class ESPLoader(object):
|
||||
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
|
||||
|
Reference in New Issue
Block a user