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:
Jakub Kocka
2023-10-11 10:10:24 +02:00
parent ef02d52044
commit d61da7785e

View File

@@ -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