summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/atmel-samd/common-hal/pulseio/PulseIn.c2
-rw-r--r--ports/atmel-samd/common-hal/rtc/RTC.c4
-rw-r--r--ports/cxd56/common-hal/pulseio/PulseIn.c2
-rw-r--r--ports/mimxrt10xx/common-hal/pulseio/PulseIn.c2
-rw-r--r--ports/nrf/common-hal/pulseio/PulseIn.c2
-rw-r--r--ports/stm/common-hal/pulseio/PulseIn.c2
-rw-r--r--py/obj.c6
-rw-r--r--py/objdict.c2
-rw-r--r--py/objint.c4
-rw-r--r--py/objlist.c2
-rw-r--r--py/objset.c2
-rw-r--r--py/runtime.c8
-rw-r--r--py/runtime.h1
-rw-r--r--shared-bindings/i2cperipheral/I2CPeripheral.c2
-rw-r--r--shared-bindings/ps2io/Ps2.c2
-rw-r--r--shared-bindings/time/__init__.c2
16 files changed, 29 insertions, 16 deletions
diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c
index ae58b089d..be8165a5a 100644
--- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c
+++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c
@@ -298,7 +298,7 @@ void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) {
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
if (self->len == 0) {
- mp_raise_IndexError(translate("pop from an empty PulseIn"));
+ mp_raise_IndexError_varg(translate("pop from empty %s"), "PulseIn");
}
common_hal_mcu_disable_interrupts();
uint16_t value = self->buffer[self->start];
diff --git a/ports/atmel-samd/common-hal/rtc/RTC.c b/ports/atmel-samd/common-hal/rtc/RTC.c
index 203187b4f..3473165db 100644
--- a/ports/atmel-samd/common-hal/rtc/RTC.c
+++ b/ports/atmel-samd/common-hal/rtc/RTC.c
@@ -68,7 +68,11 @@ int common_hal_rtc_get_calibration(void) {
void common_hal_rtc_set_calibration(int calibration) {
if (calibration > 127 || calibration < -127) {
+#if CIRCUITPY_FULL_BUILD
mp_raise_ValueError(translate("calibration value out of range +/-127"));
+#else
+ mp_raise_ValueError(translate("calibration is out of range"));
+#endif
}
hri_rtcmode0_write_FREQCORR_SIGN_bit(RTC, calibration < 0 ? 0 : 1);
diff --git a/ports/cxd56/common-hal/pulseio/PulseIn.c b/ports/cxd56/common-hal/pulseio/PulseIn.c
index 221fa5b6e..045acc9d2 100644
--- a/ports/cxd56/common-hal/pulseio/PulseIn.c
+++ b/ports/cxd56/common-hal/pulseio/PulseIn.c
@@ -160,7 +160,7 @@ void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t *self) {
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
if (self->len == 0) {
- mp_raise_IndexError(translate("pop from an empty PulseIn"));
+ mp_raise_IndexError_varg(translate("pop from empty %s"), "PulseIn");
}
common_hal_mcu_disable_interrupts();
uint16_t value = self->buffer[self->start];
diff --git a/ports/mimxrt10xx/common-hal/pulseio/PulseIn.c b/ports/mimxrt10xx/common-hal/pulseio/PulseIn.c
index ec0290861..e89a49e80 100644
--- a/ports/mimxrt10xx/common-hal/pulseio/PulseIn.c
+++ b/ports/mimxrt10xx/common-hal/pulseio/PulseIn.c
@@ -201,7 +201,7 @@ void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) {
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
// if (self->len == 0) {
-// mp_raise_IndexError(translate("pop from an empty PulseIn"));
+// mp_raise_IndexError_varg(translate("pop from empty %s"), "PulseIn");
// }
// common_hal_mcu_disable_interrupts();
// uint16_t value = self->buffer[self->start];
diff --git a/ports/nrf/common-hal/pulseio/PulseIn.c b/ports/nrf/common-hal/pulseio/PulseIn.c
index be2903e44..80ff2c529 100644
--- a/ports/nrf/common-hal/pulseio/PulseIn.c
+++ b/ports/nrf/common-hal/pulseio/PulseIn.c
@@ -284,7 +284,7 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self, int16_
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
if (self->len == 0) {
- mp_raise_IndexError(translate("pop from an empty PulseIn"));
+ mp_raise_IndexError_varg(translate("pop from empty %s"), "PulseIn");
}
if ( !self->paused ) {
diff --git a/ports/stm/common-hal/pulseio/PulseIn.c b/ports/stm/common-hal/pulseio/PulseIn.c
index 4052c240f..b43fdd554 100644
--- a/ports/stm/common-hal/pulseio/PulseIn.c
+++ b/ports/stm/common-hal/pulseio/PulseIn.c
@@ -258,7 +258,7 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self, int16_
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
if (self->len == 0) {
- mp_raise_IndexError(translate("pop from an empty PulseIn"));
+ mp_raise_IndexError_varg(translate("pop from empty %s"), "PulseIn");
}
HAL_NVIC_DisableIRQ(self->irq);
uint16_t value = self->buffer[self->start];
diff --git a/py/obj.c b/py/obj.c
index 7644b5de8..2b0c46f49 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -263,7 +263,7 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
mp_raise_TypeError(translate("can't convert to int"));
} else {
mp_raise_TypeError_varg(
- translate("can't convert %s to int"), mp_obj_get_type_str(arg));
+ translate("can't convert %s to %s"), mp_obj_get_type_str(arg), "int");
}
}
}
@@ -326,7 +326,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
mp_raise_TypeError(translate("can't convert to float"));
} else {
mp_raise_TypeError_varg(
- translate("can't convert %s to float"), mp_obj_get_type_str(arg));
+ translate("can't convert %s to %s"), mp_obj_get_type_str(arg), "float");
}
}
@@ -359,7 +359,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
mp_raise_TypeError(translate("can't convert to complex"));
} else {
mp_raise_TypeError_varg(
- translate("can't convert %s to complex"), mp_obj_get_type_str(arg));
+ translate("can't convert %s to %s"), mp_obj_get_type_str(arg), "complex");
}
}
}
diff --git a/py/objdict.c b/py/objdict.c
index 39169fe1a..6ddf7ddde 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -313,7 +313,7 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) {
size_t cur = 0;
mp_map_elem_t *next = dict_iter_next(self, &cur);
if (next == NULL) {
- mp_raise_msg(&mp_type_KeyError, translate("popitem(): dictionary is empty"));
+ mp_raise_msg_varg(&mp_type_KeyError, translate("pop from empty %s"), "dict");
}
self->map.used--;
mp_obj_t items[] = {next->key, next->value};
diff --git a/py/objint.c b/py/objint.c
index 82f5aadd1..7726fb8d8 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -141,9 +141,9 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
int cl = fpclassify(val);
if (cl == FP_INFINITE) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, translate("can't convert inf to int")));
+ mp_raise_OverflowError_varg(translate("can't convert %s to %s"), "inf", "int");
} else if (cl == FP_NAN) {
- mp_raise_ValueError(translate("can't convert NaN to int"));
+ mp_raise_ValueError_varg(translate("can't convert %s to %s"), "NaN", "int");
} else {
mp_fp_as_int_class_t icl = mp_classify_fp_as_int(val);
if (icl == MP_FP_CLASS_FIT_SMALLINT) {
diff --git a/py/objlist.c b/py/objlist.c
index 9242020d4..b2de72374 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -274,7 +274,7 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) {
mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
mp_obj_list_t *self = mp_instance_cast_to_native_base(args[0], &mp_type_list);
if (self->len == 0) {
- mp_raise_IndexError(translate("pop from empty list"));
+ mp_raise_IndexError_varg(translate("pop from empty %s"), "list");
}
size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
mp_obj_t ret = self->items[index];
diff --git a/py/objset.c b/py/objset.c
index d986c6dda..82b10e7e8 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -368,7 +368,7 @@ STATIC mp_obj_t set_pop(mp_obj_t self_in) {
mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t obj = mp_set_remove_first(&self->set);
if (obj == MP_OBJ_NULL) {
- mp_raise_msg(&mp_type_KeyError, translate("pop from an empty set"));
+ mp_raise_IndexError_varg(translate("pop from empty %s"), "set");
}
return obj;
}
diff --git a/py/runtime.c b/py/runtime.c
index 91ead1fba..c0a4f44a1 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -1546,6 +1546,14 @@ NORETURN void mp_raise_IndexError(const compressed_string_t *msg) {
mp_raise_msg(&mp_type_IndexError, msg);
}
+NORETURN void mp_raise_IndexError_varg(const compressed_string_t *fmt, ...) {
+ va_list argptr;
+ va_start(argptr,fmt);
+ mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_IndexError, fmt, argptr);
+ va_end(argptr);
+ nlr_raise(exception);
+}
+
NORETURN void mp_raise_ValueError(const compressed_string_t *msg) {
mp_raise_msg(&mp_type_ValueError, msg);
}
diff --git a/py/runtime.h b/py/runtime.h
index d3a82333e..ed37f90d9 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -160,6 +160,7 @@ NORETURN void mp_raise_AttributeError(const compressed_string_t *msg);
NORETURN void mp_raise_RuntimeError(const compressed_string_t *msg);
NORETURN void mp_raise_ImportError(const compressed_string_t *msg);
NORETURN void mp_raise_IndexError(const compressed_string_t *msg);
+NORETURN void mp_raise_IndexError_varg(const compressed_string_t *msg, ...);
NORETURN void mp_raise_OSError(int errno_);
NORETURN void mp_raise_OSError_errno_str(int errno_, mp_obj_t str);
NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
diff --git a/shared-bindings/i2cperipheral/I2CPeripheral.c b/shared-bindings/i2cperipheral/I2CPeripheral.c
index cfebd472e..39f787062 100644
--- a/shared-bindings/i2cperipheral/I2CPeripheral.c
+++ b/shared-bindings/i2cperipheral/I2CPeripheral.c
@@ -86,7 +86,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type,
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
mp_int_t value;
if (!mp_obj_get_int_maybe(item, &value)) {
- mp_raise_TypeError(translate("can't convert address to int"));
+ mp_raise_TypeError_varg(translate("can't convert %s to %s"), "address", "int");
}
if (value < 0x00 || value > 0x7f) {
mp_raise_ValueError(translate("address out of bounds"));
diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c
index 15731ea40..64d93f6ad 100644
--- a/shared-bindings/ps2io/Ps2.c
+++ b/shared-bindings/ps2io/Ps2.c
@@ -133,7 +133,7 @@ STATIC mp_obj_t ps2io_ps2_obj_popleft(mp_obj_t self_in) {
int b = common_hal_ps2io_ps2_popleft(self);
if (b < 0) {
- mp_raise_IndexError(translate("Pop from an empty Ps2 buffer"));
+ mp_raise_IndexError_varg(translate("pop from empty %s"), "Ps2 buffer");
}
return MP_OBJ_NEW_SMALL_INT(b);
}
diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c
index 262da17fd..f7382b1ac 100644
--- a/shared-bindings/time/__init__.c
+++ b/shared-bindings/time/__init__.c
@@ -280,7 +280,7 @@ STATIC mp_obj_t time_mktime(mp_obj_t t) {
mp_obj_tuple_get(t, &len, &elem);
if (len != 9) {
- mp_raise_TypeError(translate("function takes exactly 9 arguments"));
+ mp_raise_TypeError_varg(translate("function takes %d positional arguments but %d were given"), 9);
}
if (mp_obj_get_int(elem[0]) < 2000) {