Skip to content

Commit 71c9689

Browse files
committed
refactor error messages to save space
1 parent 6002f22 commit 71c9689

File tree

17 files changed

+47
-72
lines changed

17 files changed

+47
-72
lines changed

locale/circuitpython.pot

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,19 @@ msgid ""
8989
msgstr ""
9090

9191
#: ports/atmel-samd/common-hal/alarm/__init__.c
92-
#: ports/cxd56/common-hal/analogio/AnalogOut.c ports/cxd56/common-hal/rtc/RTC.c
93-
#: ports/espressif/common-hal/rtc/RTC.c
92+
#: ports/atmel-samd/common-hal/alarm/touch/TouchAlarm.c
93+
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
94+
#: ports/atmel-samd/common-hal/busio/SPI.c
95+
#: ports/cxd56/common-hal/analogio/AnalogOut.c
96+
#: ports/cxd56/common-hal/busio/SPI.c ports/cxd56/common-hal/rtc/RTC.c
97+
#: ports/espressif/common-hal/busio/SPI.c ports/espressif/common-hal/rtc/RTC.c
9498
#: ports/mimxrt10xx/common-hal/analogio/AnalogOut.c
99+
#: ports/mimxrt10xx/common-hal/busio/SPI.c
95100
#: ports/mimxrt10xx/common-hal/rtc/RTC.c ports/nrf/common-hal/alarm/__init__.c
96-
#: ports/nrf/common-hal/analogio/AnalogOut.c ports/nrf/common-hal/rtc/RTC.c
97-
#: ports/raspberrypi/common-hal/alarm/__init__.c
101+
#: ports/nrf/common-hal/analogio/AnalogOut.c ports/nrf/common-hal/busio/SPI.c
102+
#: ports/nrf/common-hal/rtc/RTC.c ports/raspberrypi/common-hal/alarm/__init__.c
98103
#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
104+
#: ports/raspberrypi/common-hal/busio/SPI.c
99105
#: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c
100106
#: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c
101107
#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c
@@ -112,6 +118,10 @@ msgstr ""
112118
msgid "%q and %q must be different"
113119
msgstr ""
114120

121+
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
122+
msgid "%q and %q must share a clock unit"
123+
msgstr ""
124+
115125
#: shared-bindings/microcontroller/Pin.c
116126
msgid "%q contains duplicate pins"
117127
msgstr ""
@@ -241,6 +251,10 @@ msgstr ""
241251
msgid "%q step cannot be zero"
242252
msgstr ""
243253

254+
#: shared-module/bitbangio/I2C.c
255+
msgid "%q too long"
256+
msgstr ""
257+
244258
#: py/bc.c py/objnamedtuple.c
245259
msgid "%q() takes %d positional arguments but %d were given"
246260
msgstr ""
@@ -419,12 +433,6 @@ msgstr ""
419433
msgid "3-arg pow() not supported"
420434
msgstr ""
421435

422-
#: ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c
423-
#: ports/atmel-samd/common-hal/countio/Counter.c
424-
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
425-
msgid "A hardware interrupt channel is already in use"
426-
msgstr ""
427-
428436
#: ports/espressif/common-hal/analogio/AnalogIn.c
429437
msgid "ADC2 is being used by WiFi"
430438
msgstr ""
@@ -595,10 +603,6 @@ msgstr ""
595603
msgid "Bit clock and word select must be sequential pins"
596604
msgstr ""
597605

598-
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
599-
msgid "Bit clock and word select must share a clock unit"
600-
msgstr ""
601-
602606
#: shared-bindings/bitmaptools/__init__.c
603607
msgid "Bitmap size and bits per value must match"
604608
msgstr ""
@@ -611,10 +615,6 @@ msgstr ""
611615
msgid "Both RX and TX required for flow control"
612616
msgstr ""
613617

614-
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
615-
msgid "Both pins must support hardware interrupts"
616-
msgstr ""
617-
618618
#: shared-bindings/displayio/Display.c
619619
#: shared-bindings/framebufferio/FramebufferDisplay.c
620620
msgid "Brightness not adjustable"
@@ -800,10 +800,6 @@ msgstr ""
800800
msgid "CircuitPython core code crashed hard. Whoops!\n"
801801
msgstr ""
802802

803-
#: shared-module/bitbangio/I2C.c
804-
msgid "Clock stretch too long"
805-
msgstr ""
806-
807803
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
808804
msgid "Clock unit in use"
809805
msgstr ""
@@ -921,9 +917,12 @@ msgstr ""
921917
msgid "ESP-IDF memory allocation failed"
922918
msgstr ""
923919

920+
#: ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c
921+
#: ports/atmel-samd/common-hal/countio/Counter.c
924922
#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c
925923
#: ports/atmel-samd/common-hal/ps2io/Ps2.c
926924
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
925+
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
927926
#: ports/cxd56/common-hal/pulseio/PulseIn.c
928927
msgid "EXTINT channel already in use"
929928
msgstr ""
@@ -1076,13 +1075,6 @@ msgstr ""
10761075
msgid "Group already used"
10771076
msgstr ""
10781077

1079-
#: ports/atmel-samd/common-hal/busio/SPI.c ports/cxd56/common-hal/busio/SPI.c
1080-
#: ports/espressif/common-hal/busio/SPI.c
1081-
#: ports/mimxrt10xx/common-hal/busio/SPI.c ports/nrf/common-hal/busio/SPI.c
1082-
#: ports/raspberrypi/common-hal/busio/SPI.c
1083-
msgid "Half duplex SPI is not implemented"
1084-
msgstr ""
1085-
10861078
#: supervisor/shared/safe_mode.c
10871079
msgid "Hard fault: memory access or instruction error."
10881080
msgstr ""
@@ -1508,10 +1500,15 @@ msgstr ""
15081500
msgid "No default %q bus"
15091501
msgstr ""
15101502

1503+
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c
15111504
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
15121505
msgid "No free GCLKs"
15131506
msgstr ""
15141507

1508+
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
1509+
msgid "No free GLCKs"
1510+
msgstr ""
1511+
15151512
#: shared-bindings/os/__init__.c
15161513
msgid "No hardware random available"
15171514
msgstr ""
@@ -1748,6 +1745,7 @@ msgid "Pin must be on PWM Channel B"
17481745
msgstr ""
17491746

17501747
#: ports/atmel-samd/common-hal/countio/Counter.c
1748+
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
17511749
msgid "Pin must support hardware interrupts"
17521750
msgstr ""
17531751

@@ -1888,10 +1886,6 @@ msgstr ""
18881886
msgid "Requested resource not found"
18891887
msgstr ""
18901888

1891-
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
1892-
msgid "Right channel unsupported"
1893-
msgstr ""
1894-
18951889
#: main.c
18961890
msgid "Running in safe mode! Not running saved code.\n"
18971891
msgstr ""
@@ -2086,7 +2080,6 @@ msgstr ""
20862080
msgid "Total data to write is larger than %q"
20872081
msgstr ""
20882082

2089-
#: ports/atmel-samd/common-hal/alarm/touch/TouchAlarm.c
20902083
#: ports/raspberrypi/common-hal/alarm/touch/TouchAlarm.c
20912084
#: ports/stm/common-hal/alarm/touch/TouchAlarm.c
20922085
msgid "Touch alarms not available"
@@ -2178,11 +2171,6 @@ msgstr ""
21782171
msgid "Unable to find I2C Display at %x"
21792172
msgstr ""
21802173

2181-
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c
2182-
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c
2183-
msgid "Unable to find free GCLK"
2184-
msgstr ""
2185-
21862174
#: py/parse.c
21872175
msgid "Unable to init parser"
21882176
msgstr ""
@@ -2655,11 +2643,6 @@ msgstr ""
26552643
msgid "can't convert %q to %q"
26562644
msgstr ""
26572645

2658-
#: py/obj.c
2659-
#, c-format
2660-
msgid "can't convert %s to complex"
2661-
msgstr ""
2662-
26632646
#: py/objstr.c
26642647
msgid "can't convert '%q' object to %q implicitly"
26652648
msgstr ""
@@ -2668,18 +2651,10 @@ msgstr ""
26682651
msgid "can't convert complex to float"
26692652
msgstr ""
26702653

2671-
#: py/obj.c
2654+
#: py/obj.c py/runtime.c
26722655
msgid "can't convert to %q"
26732656
msgstr ""
26742657

2675-
#: py/obj.c
2676-
msgid "can't convert to complex"
2677-
msgstr ""
2678-
2679-
#: py/runtime.c
2680-
msgid "can't convert to int"
2681-
msgstr ""
2682-
26832658
#: py/objstr.c
26842659
msgid "can't convert to str implicitly"
26852660
msgstr ""

ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static void pinalarm_set_alarms_light(size_t n_alarms, const mp_obj_t *alarms) {
235235
case PINALARM_ERR_NOEXTINT:
236236
raise_ValueError_invalid_pin();
237237
case PINALARM_ERR_NOCHANNEL:
238-
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
238+
mp_raise_RuntimeError(translate("EXTINT channel already in use"));
239239
default:
240240
mp_raise_RuntimeError(translate("Unknown reason."));
241241
}

ports/atmel-samd/common-hal/alarm/touch/TouchAlarm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
#include "shared-bindings/microcontroller/__init__.h"
2929

3030
void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) {
31-
mp_raise_NotImplementedError(translate("Touch alarms not available"));
31+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_TouchAlarm);
3232
}

ports/atmel-samd/common-hal/audiobusio/I2SOut.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
157157
raise_ValueError_invalid_pin_name(MP_QSTR_word_select);
158158
}
159159
if (bc_clock_unit != ws_clock_unit) {
160-
mp_raise_ValueError(translate("Bit clock and word select must share a clock unit"));
160+
mp_raise_ValueError_varg(translate("%q and %q must share a clock unit"), MP_QSTR_bit_clock, MP_QSTR_word_select);
161161
}
162162
if (serializer == 0xff) {
163163
raise_ValueError_invalid_pin_name(MP_QSTR_data);
@@ -241,7 +241,7 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t *self,
241241
// Find a free GCLK to generate the MCLK signal.
242242
uint8_t gclk = find_free_gclk(divisor);
243243
if (gclk > GCLK_GEN_NUM) {
244-
mp_raise_RuntimeError(translate("Unable to find free GCLK"));
244+
mp_raise_RuntimeError(translate("No free GLCKs"));
245245
}
246246
self->gclk = gclk;
247247

ports/atmel-samd/common-hal/audiobusio/PDMIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self,
195195
// Find a free GCLK to generate the MCLK signal.
196196
uint8_t gclk = find_free_gclk(clock_divisor);
197197
if (gclk > GCLK_GEN_NUM) {
198-
mp_raise_RuntimeError(translate("Unable to find free GCLK"));
198+
mp_raise_RuntimeError(translate("No free GCLKs"));
199199
}
200200
self->gclk = gclk;
201201

ports/atmel-samd/common-hal/audioio/AudioOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
133133
}
134134
#ifdef SAMD21
135135
if (right_channel != NULL) {
136-
mp_raise_ValueError(translate("Right channel unsupported"));
136+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_right_channel);
137137
}
138138
if (left_channel != &pin_PA02) {
139139
raise_ValueError_invalid_pin();

ports/atmel-samd/common-hal/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
5959
uint8_t dopo = 255;
6060

6161
if (half_duplex) {
62-
mp_raise_NotImplementedError(translate("Half duplex SPI is not implemented"));
62+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_half_duplex);
6363
}
6464

6565
// Ensure the object starts in its deinit state.

ports/atmel-samd/common-hal/countio/Counter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void common_hal_countio_counter_construct(countio_counter_obj_t *self,
1818

1919
if (eic_get_enable()) {
2020
if (!eic_channel_free(pin->extint_channel)) {
21-
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
21+
mp_raise_RuntimeError(translate("EXTINT channel already in use"));
2222
}
2323
} else {
2424
turn_on_external_interrupt_controller();

ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t *self,
3939
const mcu_pin_obj_t *pin_a, const mcu_pin_obj_t *pin_b) {
4040
if (!pin_a->has_extint || !pin_b->has_extint) {
41-
mp_raise_RuntimeError(translate("Both pins must support hardware interrupts"));
41+
mp_raise_RuntimeError(translate("Pin must support hardware interrupts"));
4242
}
4343

4444
// TODO: The SAMD51 has a peripheral dedicated to quadrature encoder debugging. Use it instead
4545
// of the external interrupt.
4646

4747
if (eic_get_enable()) {
4848
if (!eic_channel_free(pin_a->extint_channel) || !eic_channel_free(pin_b->extint_channel)) {
49-
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
49+
mp_raise_RuntimeError(translate("EXTINT channel already in use"));
5050
}
5151
} else {
5252
turn_on_external_interrupt_controller();

ports/cxd56/common-hal/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
4040
int port = -1;
4141

4242
if (half_duplex) {
43-
mp_raise_NotImplementedError(translate("Half duplex SPI is not implemented"));
43+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_half_duplex);
4444
}
4545

4646
if (clock->number == PIN_SPI4_SCK &&

ports/espressif/common-hal/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
8888
};
8989

9090
if (half_duplex) {
91-
mp_raise_NotImplementedError(translate("Half duplex SPI is not implemented"));
91+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_half_duplex);
9292
}
9393

9494
for (spi_host_device_t host_id = SPI2_HOST; host_id < SOC_SPI_PERIPH_NUM; host_id++) {

ports/mimxrt10xx/common-hal/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
9999
bool spi_taken = false;
100100

101101
if (half_duplex) {
102-
mp_raise_NotImplementedError(translate("Half duplex SPI is not implemented"));
102+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_half_duplex);
103103
}
104104

105105
for (uint i = 0; i < sck_count; i++) {

ports/nrf/common-hal/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate)
146146
void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) {
147147

148148
if (half_duplex) {
149-
mp_raise_NotImplementedError(translate("Half duplex SPI is not implemented"));
149+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_half_duplex);
150150
}
151151

152152
// Find a free instance, with most desirable (highest freq and not shared) allocated first.

ports/raspberrypi/common-hal/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
5858
size_t instance_index = NO_INSTANCE;
5959

6060
if (half_duplex) {
61-
mp_raise_NotImplementedError(translate("Half duplex SPI is not implemented"));
61+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_half_duplex);
6262
}
6363

6464
if (clock->number % 4 == 2) {

py/obj.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ bool mp_obj_get_complex_maybe(mp_obj_t arg, mp_float_t *real, mp_float_t *imag)
482482
void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
483483
if (!mp_obj_get_complex_maybe(arg, real, imag)) {
484484
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
485-
mp_raise_TypeError(MP_ERROR_TEXT("can't convert to complex"));
485+
mp_raise_TypeError_varg(MP_ERROR_TEXT("can't convert to %q"), MP_QSTR_complex);
486486
#else
487487
mp_raise_TypeError_varg(
488-
MP_ERROR_TEXT("can't convert %s to complex"), mp_obj_get_type_str(arg));
488+
MP_ERROR_TEXT("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_complex);
489489
#endif
490490
}
491491
}

py/runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
300300
// In this case provide a more focused error message to not confuse, e.g. chr(1.0)
301301
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
302302
if (op == MP_UNARY_OP_INT) {
303-
mp_raise_TypeError(MP_ERROR_TEXT("can't convert to int"));
303+
mp_raise_TypeError_varg(MP_ERROR_TEXT("can't convert to %q"), MP_QSTR_int);
304304
} else {
305305
mp_raise_TypeError(MP_ERROR_TEXT("unsupported type for operator"));
306306
}

shared-module/bitbangio/I2C.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ STATIC void scl_release(bitbangio_i2c_obj_t *self) {
5656
common_hal_digitalio_digitalinout_switch_to_output(&self->scl, true, DRIVE_MODE_OPEN_DRAIN);
5757
// raise exception on timeout
5858
if (count == 0) {
59-
mp_raise_msg(&mp_type_TimeoutError, translate("Clock stretch too long"));
59+
mp_raise_msg_varg(&mp_type_TimeoutError, translate("%q too long"), MP_QSTR_timeout);
6060
}
6161
}
6262

0 commit comments

Comments
 (0)