File tree 4 files changed +22
-2
lines changed 4 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,8 @@ extern const struct _mp_obj_module_t usb_hid_module;
188
188
#define MICROPY_PY_BUILTINS_FROZENSET (1)
189
189
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
190
190
#define MICROPY_PY_BUILTINS_REVERSED (1)
191
+ #define MICROPY_PY_UERRNO (1)
192
+ #define MICROPY_PY_UERRNO_ERRORCODE (0)
191
193
#define MICROPY_PY_URE (1)
192
194
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
193
195
#define MICROPY_PY_FRAMEBUF (1)
Original file line number Diff line number Diff line change @@ -100,6 +100,20 @@ const mp_obj_module_t mp_module_uerrno = {
100
100
};
101
101
102
102
qstr mp_errno_to_str (mp_obj_t errno_val ) {
103
+ // For commonly encountered errors, return human readable strings
104
+ if (MP_OBJ_IS_SMALL_INT (errno_val )) {
105
+ switch (MP_OBJ_SMALL_INT_VALUE (errno_val )) {
106
+ case EPERM : return MP_QSTR_Permission_space_denied ;
107
+ case ENOENT : return MP_QSTR_No_space_such_space_file_slash_directory ;
108
+ case EIO : return MP_QSTR_Input_slash_output_space_error ;
109
+ case EACCES : return MP_QSTR_Permission_space_denied ;
110
+ case EEXIST : return MP_QSTR_File_space_exists ;
111
+ case ENODEV : return MP_QSTR_Unsupported_space_operation ;
112
+ case EINVAL : return MP_QSTR_Invalid_space_argument ;
113
+ }
114
+ }
115
+
116
+ // Otherwise, return the Exxxx string for that error code
103
117
#if MICROPY_PY_UERRNO_ERRORCODE
104
118
// We have the errorcode dict so can do a lookup using the hash map
105
119
mp_map_elem_t * elem = mp_map_lookup ((mp_map_t * )& errorcode_dict .map , errno_val , MP_MAP_LOOKUP );
Original file line number Diff line number Diff line change 11
11
12
12
# check that errors are rendered in a nice way
13
13
msg = str (OSError (uerrno .EIO ))
14
- print (msg [:7 ], msg [- 5 :])
14
+ print (msg [:7 ], msg [msg .find (']' ):])
15
+
16
+ msg = str (OSError (uerrno .ENOBUFS ))
17
+ print (msg [:7 ], msg [msg .find (']' ):])
15
18
16
19
# check that unknown errno is still rendered
17
20
print (str (OSError (9999 )))
Original file line number Diff line number Diff line change 1
1
<class 'int'>
2
- [Errno ] EIO
2
+ [Errno ] Input/output error
3
+ [Errno ] ENOBUFS
3
4
9999
You can’t perform that action at this time.
0 commit comments