8000 Human readable OSError messages by godlygeek · Pull Request #837 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Human readable OSError messages #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Display human readable strings for common OSErrors
Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
  • Loading branch information
godlygeek committed May 14, 2018
commit 5833cbe6dec64a980054ed0b408033cff9d2f22e
14 changes: 14 additions & 0 deletions py/moduerrno.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
0