tools/mpremote: Support OSError's on targets without errno.
Some checks failed
JavaScript code lint and formatting with Biome / eslint (push) Has been cancelled
Check code formatting / code-formatting (push) Has been cancelled
Check spelling with codespell / codespell (push) Has been cancelled
Build docs / build (push) Has been cancelled
Check examples / embedding (push) Has been cancelled
Package mpremote / build (push) Has been cancelled
.mpy file format and tools / test (push) Has been cancelled
Build ports metadata / build (push) Has been cancelled
alif port / build_alif (alif_ae3_build) (push) Has been cancelled
cc3200 port / build (push) Has been cancelled
esp32 port / build_idf (esp32_build_cmod_spiram_s2) (push) Has been cancelled
esp32 port / build_idf (esp32_build_s3_c3) (push) Has been cancelled
esp8266 port / build (push) Has been cancelled
mimxrt port / build (push) Has been cancelled
nrf port / build (push) Has been cancelled
powerpc port / build (push) Has been cancelled
qemu port / build_and_test_arm (bigendian) (push) Has been cancelled
qemu port / build_and_test_arm (sabrelite) (push) Has been cancelled
qemu port / build_and_test_arm (thumb) (push) Has been cancelled
qemu port / build_and_test_rv32 (push) Has been cancelled
renesas-ra port / build_renesas_ra_board (push) Has been cancelled
rp2 port / build (push) Has been cancelled
samd port / build (push) Has been cancelled
stm32 port / build_stm32 (stm32_misc_build) (push) Has been cancelled
stm32 port / build_stm32 (stm32_nucleo_build) (push) Has been cancelled
stm32 port / build_stm32 (stm32_pyb_build) (push) Has been cancelled
unix port / minimal (push) Has been cancelled
unix port / reproducible (push) Has been cancelled
unix port / standard (push) Has been cancelled
unix port / standard_v2 (push) Has been cancelled
unix port / coverage (push) Has been cancelled
unix port / coverage_32bit (push) Has been cancelled
unix port / nanbox (push) Has been cancelled
unix port / float (push) Has been cancelled
unix port / stackless_clang (push) Has been cancelled
unix port / float_clang (push) Has been cancelled
unix port / settrace_stackless (push) Has been cancelled
unix port / macos (push) Has been cancelled
unix port / qemu_mips (push) Has been cancelled
unix port / qemu_arm (push) Has been cancelled
unix port / qemu_riscv64 (push) Has been cancelled
unix port / sanitize_address (push) Has been cancelled
unix port / sanitize_undefined (push) Has been cancelled
webassembly port / build (push) Has been cancelled
windows port / build-vs (Debug, x64, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, x64, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x86, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, x86, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x64, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x64, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x86, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x86, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x86, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x86, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, dev) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, standard) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, dev) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, standard) (push) Has been cancelled
windows port / cross-build-on-linux (push) Has been cancelled
zephyr port / build (push) Has been cancelled
Python code lint and formatting with ruff / ruff (push) Has been cancelled

Targets without the `errno` module enabled will not render `OSError`s
with the name of the error.  Instead they just print the numeric error
code.

Add support for such targets by explicitly recognising certain error codes.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-06-23 12:42:01 +10:00
parent da3709a738
commit 05342b013d
2 changed files with 65 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
import errno
# This table maps numeric values defined by `py/mperrno.h` to host errno code.
MP_ERRNO_TABLE = {
1: errno.EPERM,
2: errno.ENOENT,
3: errno.ESRCH,
4: errno.EINTR,
5: errno.EIO,
6: errno.ENXIO,
7: errno.E2BIG,
8: errno.ENOEXEC,
9: errno.EBADF,
10: errno.ECHILD,
11: errno.EAGAIN,
12: errno.ENOMEM,
13: errno.EACCES,
14: errno.EFAULT,
15: errno.ENOTBLK,
16: errno.EBUSY,
17: errno.EEXIST,
18: errno.EXDEV,
19: errno.ENODEV,
20: errno.ENOTDIR,
21: errno.EISDIR,
22: errno.EINVAL,
23: errno.ENFILE,
24: errno.EMFILE,
25: errno.ENOTTY,
26: errno.ETXTBSY,
27: errno.EFBIG,
28: errno.ENOSPC,
29: errno.ESPIPE,
30: errno.EROFS,
31: errno.EMLINK,
32: errno.EPIPE,
33: errno.EDOM,
34: errno.ERANGE,
95: errno.EOPNOTSUPP,
97: errno.EAFNOSUPPORT,
98: errno.EADDRINUSE,
103: errno.ECONNABORTED,
104: errno.ECONNRESET,
105: errno.ENOBUFS,
106: errno.EISCONN,
107: errno.ENOTCONN,
110: errno.ETIMEDOUT,
111: errno.ECONNREFUSED,
113: errno.EHOSTUNREACH,
114: errno.EALREADY,
115: errno.EINPROGRESS,
125: errno.ECANCELED,
}

View File

@@ -24,8 +24,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import ast, errno, hashlib, os, sys
import ast, errno, hashlib, os, re, sys
from collections import namedtuple
from .mp_errno import MP_ERRNO_TABLE
def stdout_write_bytes(b):
@@ -62,6 +63,16 @@ def _convert_filesystem_error(e, info):
]:
if estr in e.error_output:
return OSError(code, info)
# Some targets don't render OSError with the name of the errno, so in these
# cases support an explicit mapping of errnos to known numeric codes.
error_lines = e.error_output.splitlines()
match = re.match(r"OSError: (\d+)$", error_lines[-1])
if match:
value = int(match.group(1), 10)
if value in MP_ERRNO_TABLE:
return OSError(MP_ERRNO_TABLE[value], info)
return e