fix: close port when connect fails

This fixes a bug where the serial port is not closed when the connect
fails. This can cause the port to be left open and unusable.
This occurs when esptool is used as a module and detect_chip is called.

Closes https://github.com/espressif/esptool/issues/1044
This commit is contained in:
Jaroslav Burian
2025-01-08 10:26:57 +01:00
committed by Radim Karniš
parent 12095b2b31
commit d99c972156

View File

@@ -737,7 +737,7 @@ class ESPLoader(object):
" if ESP32-C2 doesn't connect"
" (at least 115200 Bd is recommended)."
)
self._port.close()
raise FatalError(
"Failed to connect to {}: {}"
f"{additional_msg}"