diff options
| author | Matt Wozniski <mwozniski@bloomberg.net> | 2018-05-14 14:54:39 -0400 |
|---|---|---|
| committer | Matt Wozniski <mwozniski@bloomberg.net> | 2018-05-14 15:12:40 -0400 |
| commit | 5833cbe6dec64a980054ed0b408033cff9d2f22e (patch) | |
| tree | c08fef45f1cad602761c184074e4b2e2ca561b3d | |
| parent | 0518cc1d94a3c54e767496b38287333102b9d52a (diff) | |
Display human readable strings for common OSErrors
Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
| -rw-r--r-- | py/moduerrno.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/py/moduerrno.c b/py/moduerrno.c index de66c941b..ce8a6bf89 100644 --- a/py/moduerrno.c +++ b/py/moduerrno.c @@ -100,6 +100,20 @@ const mp_obj_module_t mp_module_uerrno = { }; qstr mp_errno_to_str(mp_obj_t errno_val) { + // For commonly encountered errors, return human readable strings + if (MP_OBJ_IS_SMALL_INT(errno_val)) { + switch (MP_OBJ_SMALL_INT_VALUE(errno_val)) { + case EPERM: return MP_QSTR_Permission_space_denied; + case ENOENT: return MP_QSTR_No_space_such_space_file_slash_directory; + case EIO: return MP_QSTR_Input_slash_output_space_error; + case EACCES: return MP_QSTR_Permission_space_denied; + case EEXIST: return MP_QSTR_File_space_exists; + case ENODEV: return MP_QSTR_Unsupported_space_operation; + case EINVAL: return MP_QSTR_Invalid_space_argument; + } + } + + // Otherwise, return the Exxxx string for that error code #if MICROPY_PY_UERRNO_ERRORCODE // We have the errorcode dict so can do a lookup using the hash map mp_map_elem_t *elem = mp_map_lookup((mp_map_t*)&errorcode_dict.map, errno_val, MP_MAP_LOOKUP); |
