diff options
| author | Drew Fustini <drew@pdp7.com> | 2020-02-10 00:11:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-10 00:11:35 +0100 |
| commit | 7bdc8b36a697cff816e6e449706bb060f66b3229 (patch) | |
| tree | 5e7ef62c0a1635febaf90734638d161d9f9228bd /py/objexcept.c | |
| parent | 3aed0a1fd721550bedd8f2258707f58eb9927404 (diff) | |
| parent | b93d6e861b80d34ff3b09f4f84a85a6bfd531f3d (diff) | |
Merge pull request #1 from adafruit/master
update to adafruit master
Diffstat (limited to 'py/objexcept.c')
| -rw-r--r-- | py/objexcept.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index c33ada0d6..b7a536c5e 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -112,17 +112,23 @@ void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin if (o->args == NULL || o->args->len == 0) { mp_print_str(print, ""); return; - } else if (o->args->len == 1) { + } + if (MP_OBJ_IS_SMALL_INT(o->args->items[0]) && + mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(o->base.type), MP_OBJ_FROM_PTR(&mp_type_OSError)) && + o->args->len <= 2) { // try to provide a nice OSError error message - if (MP_OBJ_IS_SMALL_INT(o->args->items[0]) && - mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(o->base.type), MP_OBJ_FROM_PTR(&mp_type_OSError))) { - char decompressed[50]; - const char *msg = mp_common_errno_to_str(o->args->items[0], decompressed, sizeof(decompressed)); - if (msg != NULL) { - mp_printf(print, "[Errno " INT_FMT "] %s", MP_OBJ_SMALL_INT_VALUE(o->args->items[0]), msg); - return; + char decompressed[50]; + const char *msg = mp_common_errno_to_str(o->args->items[0], decompressed, sizeof(decompressed)); + if (msg != NULL) { + mp_printf(print, "[Errno " INT_FMT "] %s", MP_OBJ_SMALL_INT_VALUE(o->args->items[0]), msg); + // if second arg exists, it is filename. + if (o->args->len == 2) { + mp_printf(print, ": '%s'", mp_obj_str_get_str(o->args->items[1])); } + return; } + } + if (o->args->len == 1) { mp_obj_print_helper(print, o->args->items[0], PRINT_STR); return; } |
