File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -188,6 +188,8 @@ extern const struct _mp_obj_module_t usb_hid_module;
188188 #define MICROPY_PY_BUILTINS_FROZENSET (1)
189189 #define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
190190 #define MICROPY_PY_BUILTINS_REVERSED (1)
191+ #define MICROPY_PY_UERRNO (1)
192+ #define MICROPY_PY_UERRNO_ERRORCODE (0)
191193 #define MICROPY_PY_URE (1)
192194 #define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
193195 #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 = {
100100};
101101
102102qstr 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
103117 #if MICROPY_PY_UERRNO_ERRORCODE
104118 // We have the errorcode dict so can do a lookup using the hash map
105119 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 1111
1212# check that errors are rendered in a nice way
1313msg = 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 (']' ):])
1518
1619# check that unknown errno is still rendered
1720print (str (OSError (9999 )))
Original file line number Diff line number Diff line change 11<class 'int'>
2- [Errno ] EIO
2+ [Errno ] Input/output error
3+ [Errno ] ENOBUFS
349999
You can’t perform that action at this time.
0 commit comments