Skip to content

Commit 7fe959a

Browse files
committed
fix multi-arg exception printing
1 parent 5164719 commit 7fe959a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

py/objexcept.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,22 @@ void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin
112112
if (o->args == NULL || o->args->len == 0) {
113113
mp_print_str(print, "");
114114
return;
115-
} else if (o->args->len <= 2) {
116-
// try to provide a nice OSError error message; second arg might exist (e.g. filename).
117-
if (MP_OBJ_IS_SMALL_INT(o->args->items[0]) &&
118-
mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(o->base.type), MP_OBJ_FROM_PTR(&mp_type_OSError))) {
119-
char decompressed[50];
120-
const char *msg = mp_common_errno_to_str(o->args->items[0], decompressed, sizeof(decompressed));
121-
if (msg != NULL) {
122-
mp_printf(print, "[Errno " INT_FMT "] %s", MP_OBJ_SMALL_INT_VALUE(o->args->items[0]), msg);
123-
if (o->args->len == 2) {
124-
mp_printf(print, ": '%s'", mp_obj_str_get_str(o->args->items[1]));
125-
}
126-
return;
115+
}
116+
if (MP_OBJ_IS_SMALL_INT(o->args->items[0]) &&
117+
mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(o->base.type), MP_OBJ_FROM_PTR(&mp_type_OSError)) &&
118+
o->args->len <= 2) {
119+
// try to provide a nice OSError error message
120+
char decompressed[50];
121+
const char *msg = mp_common_errno_to_str(o->args->items[0], decompressed, sizeof(decompressed));
122+
if (msg != NULL) {
123+
mp_printf(print, "[Errno " INT_FMT "] %s", MP_OBJ_SMALL_INT_VALUE(o->args->items[0]), msg);
124+
// if second arg exists, it is filename.
125+
if (o->args->len == 2) {
126+
mp_printf(print, ": '%s'", mp_obj_str_get_str(o->args->items[1]));
127127
}
128+
return;
128129
}
130+
} else if (o->args->len == 1) {
129131
mp_obj_print_helper(print, o->args->items[0], PRINT_STR);
130132
return;
131133
}

0 commit comments

Comments
 (0)