Skip to content

Commit 05342b0

Browse files
committed
tools/mpremote: Support OSError's on targets without errno.
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>
1 parent da3709a commit 05342b0

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

tools/mpremote/mpremote/mp_errno.py

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

tools/mpremote/mpremote/transport.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525
# THE SOFTWARE.
2626

27-
import ast, errno, hashlib, os, sys
27+
import ast, errno, hashlib, os, re, sys
2828
from collections import namedtuple
29+
from .mp_errno import MP_ERRNO_TABLE
2930

3031

3132
def stdout_write_bytes(b):
@@ -62,6 +63,16 @@ def _convert_filesystem_error(e, info):
6263
]:
6364
if estr in e.error_output:
6465
return OSError(code, info)
66+
67+
# Some targets don't render OSError with the name of the errno, so in these
68+
# cases support an explicit mapping of errnos to known numeric codes.
69+
error_lines = e.error_output.splitlines()
70+
match = re.match(r"OSError: (\d+)$", error_lines[-1])
71+
if match:
72+
value = int(match.group(1), 10)
73+
if value in MP_ERRNO_TABLE:
74+
return OSError(MP_ERRNO_TABLE[value], info)
75+
6576
return e
6677

6778

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy