summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-02-04 16:41:25 -0500
committerDan Halbert <halbert@halwitz.org>2020-02-04 16:41:25 -0500
commit7fe959ab39e14b000934b15d7cce13aae9f6a525 (patch)
tree482792287565afd568b1ec3d508c5be468d8b657 /py
parent5164719e67878418cff51d26f40e4813da02bc83 (diff)
fix multi-arg exception printing
Diffstat (limited to 'py')
-rw-r--r--py/objexcept.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/py/objexcept.c b/py/objexcept.c
index 8664060ec..f211b87ee 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -112,20 +112,22 @@ 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 <= 2) {
- // try to provide a nice OSError error message; second arg might exist (e.g. filename).
- 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);
- if (o->args->len == 2) {
- mp_printf(print, ": '%s'", mp_obj_str_get_str(o->args->items[1]));
- }
- return;
+ }
+ 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
+ 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;
}
+ } else if (o->args->len == 1) {
mp_obj_print_helper(print, o->args->items[0], PRINT_STR);
return;
}