8000 Display human readable strings for common OSErrors · adafruit/circuitpython@5833cbe · GitHub
[go: up one dir, main page]

Skip to content

Commit 5833cbe

Browse files
committed
Display human readable strings for common OSErrors
Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
1 parent 0518cc1 commit 5833cbe

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

py/moduerrno.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ const mp_obj_module_t mp_module_uerrno = {
100100
};
101101

102102
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
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);

0 commit comments

Comments
 (0)
0