Skip to content

Commit d25d168

Browse files
esp32/mphalport.c: Add info to OSError msg.
Change mp_printf(MP_PYTHON_PRINTER, ...) to mp_raise_msg_varg(&mp_type_OSError, ...) Signed-off-by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com> Co-Authored-By: Angus Gratton <205573+projectgus@users.noreply.github.com>
1 parent 4295f24 commit d25d168

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ports/esp32/mphalport.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ void check_esp_err_(esp_err_t code, const char *func, const int line, const char
7474
pcode = MP_EOPNOTSUPP;
7575
break;
7676
}
77+
#if MICROPY_ERROR_REPORTING > MICROPY_ERROR_REPORTING_NORMAL
78+
char err_msg[64];
79+
mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("%d, 0x%04X, '%s'" " in function '%s' at line %d in file '%s'"), pcode, code, (const char *)esp_err_to_name_r(code, err_msg, sizeof(err_msg)), func, line, file);
80+
#else
7781
// construct string object
7882
mp_obj_str_t *o_str = m_new_obj_maybe(mp_obj_str_t);
7983
if (o_str == NULL) {
@@ -84,12 +88,10 @@ void check_esp_err_(esp_err_t code, const char *func, const int line, const char
8488
o_str->data = (const byte *)esp_err_to_name(code); // esp_err_to_name ret's ptr to const str
8589
o_str->len = strlen((char *)o_str->data);
8690
o_str->hash = qstr_compute_hash(o_str->data, o_str->len);
87-
#if MICROPY_ERROR_REPORTING > MICROPY_ERROR_REPORTING_NORMAL
88-
mp_printf(MP_PYTHON_PRINTER, "Exception in function '%s' at line %d in file '%s'\n", func, line, file);
89-
#endif
9091
// raise
9192
mp_obj_t args[2] = { MP_OBJ_NEW_SMALL_INT(pcode), MP_OBJ_FROM_PTR(o_str)};
9293
nlr_raise(mp_obj_exception_make_new(&mp_type_OSError, 2, 0, args));
94+
#endif
9395
}
9496
}
9597

0 commit comments

Comments
 (0)