fix multi-arg exception printing

This commit is contained in:
Dan Halbert 2020-02-04 16:41:25 -05:00
parent 5164719e67
commit 7fe959ab39

View File

@ -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;
}