From 7fe959ab39e14b000934b15d7cce13aae9f6a525 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 4 Feb 2020 16:41:25 -0500 Subject: [PATCH] fix multi-arg exception printing --- py/objexcept.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/py/objexcept.c b/py/objexcept.c index 8664060ec5..f211b87ee0 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; }