Skip to content

Commit 9ce042a

Browse files
authored
Merge pull request adafruit#1865 from terriko/mpy_error
Make status light flash blue for incompatible mpy (fixes adafruit#1369)
2 parents 019254a + 8d9c2f3 commit 9ce042a

File tree

8 files changed

+12
-1
lines changed

8 files changed

+12
-1
lines changed

py/modbuiltins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = {
722722
{ MP_ROM_QSTR(MP_QSTR_KeyError), MP_ROM_PTR(&mp_type_KeyError) },
723723
{ MP_ROM_QSTR(MP_QSTR_LookupError), MP_ROM_PTR(&mp_type_LookupError) },
724724
{ MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_MemoryError) },
725+
{ MP_ROM_QSTR(MP_QSTR_MpyError), MP_ROM_PTR(&mp_type_MpyError) },
725726
{ MP_ROM_QSTR(MP_QSTR_NameError), MP_ROM_PTR(&mp_type_NameError) },
726727
{ MP_ROM_QSTR(MP_QSTR_NotImplementedError), MP_ROM_PTR(&mp_type_NotImplementedError) },
727728
{ MP_ROM_QSTR(MP_QSTR_OSError), MP_ROM_PTR(&mp_type_OSError) },

py/obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ extern const mp_obj_type_t mp_type_ReloadException;
599599
extern const mp_obj_type_t mp_type_KeyError;
600600
extern const mp_obj_type_t mp_type_LookupError;
601601
extern const mp_obj_type_t mp_type_MemoryError;
602+
extern const mp_obj_type_t mp_type_MpyError;
602603
extern const mp_obj_type_t mp_type_NameError;
603604
extern const mp_obj_type_t mp_type_NotImplementedError;
604605
extern const mp_obj_type_t mp_type_OSError;

py/objexcept.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
311311
MP_DEFINE_EXCEPTION(UnicodeError, ValueError)
312312
//TODO: Implement more UnicodeError subclasses which take arguments
313313
#endif
314+
MP_DEFINE_EXCEPTION(MpyError, ValueError)
314315
/*
315316
MP_DEFINE_EXCEPTION(Warning, Exception)
316317
MP_DEFINE_EXCEPTION(DeprecationWarning, Warning)

py/persistentcode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) {
220220
|| header[1] != MPY_VERSION
221221
|| header[2] != MPY_FEATURE_FLAGS
222222
|| header[3] > mp_small_int_bits()) {
223-
mp_raise_ValueError(translate("Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info."));
223+
mp_raise_MpyError(translate("Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info."));
224224
}
225225
mp_raw_code_t *rc = load_raw_code(reader);
226226
reader->close(reader->data);

py/runtime.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,10 @@ NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt,
15981598
nlr_raise(exception);
15991599
}
16001600

1601+
NORETURN void mp_raise_MpyError(const compressed_string_t *msg) {
1602+
mp_raise_msg(&mp_type_MpyError, msg);
1603+
}
1604+
16011605
#if MICROPY_STACK_CHECK || MICROPY_ENABLE_PYSTACK
16021606
NORETURN void mp_raise_recursion_depth(void) {
16031607
mp_raise_RuntimeError(translate("maximum recursion depth exceeded"));

py/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
163163
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...);
164164
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
165165
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
166+
NORETURN void mp_raise_MpyError(const compressed_string_t *msg);
166167
NORETURN void mp_raise_recursion_depth(void);
167168

168169
#if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG

supervisor/shared/rgb_led_colors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
#define NAME_ERROR WHITE
3232
#define OS_ERROR ORANGE
3333
#define VALUE_ERROR PURPLE
34+
#define MPY_ERROR BLUE
3435
#define OTHER_ERROR YELLOW

supervisor/shared/rgb_led_status.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
247247
status->exception_color = OS_ERROR;
248248
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_ValueError)) {
249249
status->exception_color = VALUE_ERROR;
250+
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_MpyError)) {
251+
status->exception_color = MPY_ERROR;
250252
} else {
251253
status->exception_color = OTHER_ERROR;
252254
}

0 commit comments

Comments
 (0)