diff --git a/py/modbuiltins.c b/py/modbuiltins.c index b4f4fca34b..124dcd05a3 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -722,6 +722,7 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_KeyError), MP_ROM_PTR(&mp_type_KeyError) }, { MP_ROM_QSTR(MP_QSTR_LookupError), MP_ROM_PTR(&mp_type_LookupError) }, { MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_MemoryError) }, + { MP_ROM_QSTR(MP_QSTR_MpyError), MP_ROM_PTR(&mp_type_MpyError) }, { MP_ROM_QSTR(MP_QSTR_NameError), MP_ROM_PTR(&mp_type_NameError) }, { MP_ROM_QSTR(MP_QSTR_NotImplementedError), MP_ROM_PTR(&mp_type_NotImplementedError) }, { MP_ROM_QSTR(MP_QSTR_OSError), MP_ROM_PTR(&mp_type_OSError) }, diff --git a/py/obj.h b/py/obj.h index ab41a1b407..ae2bff1906 100644 --- a/py/obj.h +++ b/py/obj.h @@ -599,6 +599,7 @@ extern const mp_obj_type_t mp_type_ReloadException; extern const mp_obj_type_t mp_type_KeyError; extern const mp_obj_type_t mp_type_LookupError; extern const mp_obj_type_t mp_type_MemoryError; +extern const mp_obj_type_t mp_type_MpyError; extern const mp_obj_type_t mp_type_NameError; extern const mp_obj_type_t mp_type_NotImplementedError; extern const mp_obj_type_t mp_type_OSError; diff --git a/py/objexcept.c b/py/objexcept.c index 0e9255db73..c33ada0d69 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -311,6 +311,7 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION(UnicodeError, ValueError) //TODO: Implement more UnicodeError subclasses which take arguments #endif + MP_DEFINE_EXCEPTION(MpyError, ValueError) /* MP_DEFINE_EXCEPTION(Warning, Exception) MP_DEFINE_EXCEPTION(DeprecationWarning, Warning) diff --git a/py/persistentcode.c b/py/persistentcode.c index b44b5e38d2..f6de782ed8 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -220,7 +220,7 @@ mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) { || header[1] != MPY_VERSION || header[2] != MPY_FEATURE_FLAGS || header[3] > mp_small_int_bits()) { - mp_raise_ValueError(translate("Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info.")); + mp_raise_MpyError(translate("Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info.")); } mp_raw_code_t *rc = load_raw_code(reader); reader->close(reader->data); diff --git a/py/runtime.c b/py/runtime.c index 1e01003373..1a75a3870b 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1598,6 +1598,10 @@ NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, nlr_raise(exception); } +NORETURN void mp_raise_MpyError(const compressed_string_t *msg) { + mp_raise_msg(&mp_type_MpyError, msg); +} + #if MICROPY_STACK_CHECK || MICROPY_ENABLE_PYSTACK NORETURN void mp_raise_recursion_depth(void) { mp_raise_RuntimeError(translate("maximum recursion depth exceeded")); diff --git a/py/runtime.h b/py/runtime.h index 2577c9dd53..c5a94b0b19 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -163,6 +163,7 @@ NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg); NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg); NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...); +NORETURN void mp_raise_MpyError(const compressed_string_t *msg); NORETURN void mp_raise_recursion_depth(void); #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG diff --git a/supervisor/shared/rgb_led_colors.h b/supervisor/shared/rgb_led_colors.h index cab7029811..48994ad62c 100644 --- a/supervisor/shared/rgb_led_colors.h +++ b/supervisor/shared/rgb_led_colors.h @@ -31,4 +31,5 @@ #define NAME_ERROR WHITE #define OS_ERROR ORANGE #define VALUE_ERROR PURPLE +#define MPY_ERROR BLUE #define OTHER_ERROR YELLOW diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index df9fdf8d95..209eef55eb 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -247,6 +247,8 @@ void prep_rgb_status_animation(const pyexec_result_t* result, status->exception_color = OS_ERROR; } else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_ValueError)) { status->exception_color = VALUE_ERROR; + } else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_MpyError)) { + status->exception_color = MPY_ERROR; } else { status->exception_color = OTHER_ERROR; }