Skip to content

Commit

Permalink
all: Use MP_ERROR_TEXT for all error messages.
Browse files Browse the repository at this point in the history
---

Updated for Pycopy.

Change-Id: I9e3f72bfe7decf38e3db78d46dc421779e4a4f21
Signed-off-by: Paul Sokolovsky <[email protected]>
  • Loading branch information
jimmo authored and pfalcon committed Dec 28, 2020
1 parent ddeeed2 commit 4720e5e
Show file tree
Hide file tree
Showing 191 changed files with 819 additions and 915 deletions.
2 changes: 1 addition & 1 deletion drivers/dht/dht.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) {
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE);

if (bufinfo.len < 5) {
mp_raise_ValueError("buffer too small");
mp_raise_ValueError(MP_ERROR_TEXT("buffer too small"));
}

// issue start command
Expand Down
2 changes: 1 addition & 1 deletion examples/natmod/features1/features1.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ STATIC mp_int_t fibonacci_helper(mp_int_t x) {
STATIC mp_obj_t fibonacci(mp_obj_t x_in) {
mp_int_t x = mp_obj_get_int(x_in);
if (x < 0) {
mp_raise_ValueError("can't compute negative Fibonacci number");
mp_raise_ValueError(MP_ERROR_TEXT("can't compute negative Fibonacci number"));
}
return mp_obj_new_int(fibonacci_helper(x));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/natmod/features2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ STATIC mp_obj_t productf(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_o
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_RW);
if (bufinfo.typecode != 'f') {
mp_raise_ValueError("expecting float array");
mp_raise_ValueError(MP_ERROR_TEXT("expecting float array"));
}

// Compute product, store result back in first element of array
Expand Down
2 changes: 1 addition & 1 deletion examples/natmod/ure/ure.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void mp_stack_check(void) {
// Assumes descending stack on target
volatile char dummy;
if (stack_top - &dummy >= STACK_LIMIT) {
mp_raise_msg(&mp_type_RuntimeError, "maximum recursion depth exceeded");
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("maximum recursion depth exceeded"));
}
}

Expand Down
10 changes: 5 additions & 5 deletions extmod/machine_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ STATIC mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, s
extern mp_obj_t MICROPY_PY_MACHINE_I2C_MAKE_NEW(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
return MICROPY_PY_MACHINE_I2C_MAKE_NEW(type, n_args, n_kw, args);
#else
mp_raise_ValueError("invalid I2C peripheral");
mp_raise_ValueError(MP_ERROR_TEXT("invalid I2C peripheral"));
#endif
}
--n_args;
Expand Down Expand Up @@ -367,7 +367,7 @@ STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) {
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
if (i2c_p->start == NULL) {
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("I2C operation not supported"));
}
int ret = i2c_p->start(self);
if (ret != 0) {
Expand All @@ -381,7 +381,7 @@ STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) {
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
if (i2c_p->stop == NULL) {
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("I2C operation not supported"));
}
int ret = i2c_p->stop(self);
if (ret != 0) {
Expand All @@ -395,7 +395,7 @@ STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) {
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
if (i2c_p->read == NULL) {
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("I2C operation not supported"));
}

// get the buffer to read into
Expand All @@ -419,7 +419,7 @@ STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in);
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)self->type->protocol;
if (i2c_p->write == NULL) {
mp_raise_msg(&mp_type_OSError, "I2C operation not supported");
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("I2C operation not supported"));
}

// get the buffer to write from
Expand Down
2 changes: 1 addition & 1 deletion extmod/machine_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) {
uintptr_t addr = mp_obj_int_get_truncated(addr_o);
if ((addr & (align - 1)) != 0) {
mp_raise_msg_varg(&mp_type_ValueError, "address %08x is not aligned to %d bytes", addr, align);
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("address %08x is not aligned to %d bytes"), addr, align);
}
return addr;
}
Expand Down
10 changes: 5 additions & 5 deletions extmod/machine_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mp_obj_t mp_machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
extern mp_obj_t MICROPY_PY_MACHINE_SPI_MAKE_NEW(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
return MICROPY_PY_MACHINE_SPI_MAKE_NEW(type, n_args, n_kw, args);
#else
mp_raise_ValueError("invalid SPI peripheral");
mp_raise_ValueError(MP_ERROR_TEXT("invalid SPI peripheral"));
#endif
}
--n_args;
Expand Down Expand Up @@ -119,7 +119,7 @@ STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self, mp_obj_t wr_buf, mp
mp_buffer_info_t dest;
mp_get_buffer_raise(rd_buf, &dest, MP_BUFFER_WRITE);
if (src.len != dest.len) {
mp_raise_ValueError("buffers must be the same length");
mp_raise_ValueError(MP_ERROR_TEXT("buffers must be the same length"));
}
mp_machine_spi_transfer(self, src.len, src.buf, dest.buf);
return mp_const_none;
Expand Down Expand Up @@ -202,15 +202,15 @@ STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n
self->spi.polarity = args[ARG_polarity].u_int;
self->spi.phase = args[ARG_phase].u_int;
if (args[ARG_bits].u_int != 8) {
mp_raise_ValueError("bits must be 8");
mp_raise_ValueError(MP_ERROR_TEXT("bits must be 8"));
}
if (args[ARG_firstbit].u_int != MICROPY_PY_MACHINE_SPI_MSB) {
mp_raise_ValueError("firstbit must be MSB");
mp_raise_ValueError(MP_ERROR_TEXT("firstbit must be MSB"));
}
if (args[ARG_sck].u_obj == MP_OBJ_NULL
|| args[ARG_mosi].u_obj == MP_OBJ_NULL
|| args[ARG_miso].u_obj == MP_OBJ_NULL) {
mp_raise_ValueError("must specify all of sck/mosi/miso");
mp_raise_ValueError(MP_ERROR_TEXT("must specify all of sck/mosi/miso"));
}
self->spi.sck = mp_hal_get_pin_obj(args[ARG_sck].u_obj);
self->spi.mosi = mp_hal_get_pin_obj(args[ARG_mosi].u_obj);
Expand Down
28 changes: 14 additions & 14 deletions extmod/modbluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
self->type = MP_BLUETOOTH_UUID_TYPE_16;
mp_int_t value = mp_obj_get_int(all_args[0]);
if (value > 65535) {
mp_raise_ValueError("invalid UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid UUID"));
}
self->data[0] = value & 0xff;
self->data[1] = (value >> 8) & 0xff;
Expand All @@ -112,12 +112,12 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
continue;
}
if (!unichar_isxdigit(c)) {
mp_raise_ValueError("invalid char in UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid char in UUID"));
}
c = unichar_xdigit_value(c);
uuid_i--;
if (uuid_i < 0) {
mp_raise_ValueError("UUID too long");
mp_raise_ValueError(MP_ERROR_TEXT("UUID too long"));
}
if (uuid_i % 2 == 0) {
// lower nibble
Expand All @@ -128,7 +128,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
}
}
if (uuid_i > 0) {
mp_raise_ValueError("UUID too short");
mp_raise_ValueError(MP_ERROR_TEXT("UUID too short"));
}
}
}
Expand Down Expand Up @@ -283,7 +283,7 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
if (kwargs->used == 0) {
// Get config value
if (n_args != 2) {
mp_raise_TypeError("must query one param");
mp_raise_TypeError(MP_ERROR_TEXT("must query one param"));
}

switch (mp_obj_str_get_qstr(args[1])) {
Expand All @@ -295,12 +295,12 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
case MP_QSTR_rxbuf:
return mp_obj_new_int(self->ringbuf.size);
default:
mp_raise_ValueError("unknown config param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
}
} else {
// Set config value(s)
if (n_args != 1) {
mp_raise_TypeError("can't specify pos and kw args");
mp_raise_TypeError(MP_ERROR_TEXT("can't specify pos and kw args"));
}

for (size_t i = 0; i < kwargs->alloc; ++i) {
Expand Down Expand Up @@ -341,7 +341,7 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
break;
}
default:
mp_raise_ValueError("unknown config param");
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
}
}
}
Expand All @@ -361,7 +361,7 @@ STATIC mp_obj_t bluetooth_ble_irq(size_t n_args, const mp_obj_t *pos_args, mp_ma
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_obj_t callback = args[ARG_handler].u_obj;
if (callback != mp_const_none && !mp_obj_is_callable(callback)) {
mp_raise_ValueError("invalid callback");
mp_raise_ValueError(MP_ERROR_TEXT("invalid callback"));
}

// Update the callback.
Expand Down Expand Up @@ -414,7 +414,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bluetooth_ble_gap_advertise_obj, 1, bluetooth_

STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t characteristics_in, uint16_t **handles, size_t *num_handles) {
if (!mp_obj_is_type(uuid_in, &bluetooth_uuid_type)) {
mp_raise_ValueError("invalid service UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid service UUID"));
}
mp_obj_bluetooth_uuid_t *service_uuid = MP_OBJ_TO_PTR(uuid_in);

Expand Down Expand Up @@ -451,11 +451,11 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
mp_obj_get_array(characteristic_obj, &characteristic_len, &characteristic_items);

if (characteristic_len < 2 || characteristic_len > 3) {
mp_raise_ValueError("invalid characteristic tuple");
mp_raise_ValueError(MP_ERROR_TEXT("invalid characteristic tuple"));
}
mp_obj_t uuid_obj = characteristic_items[0];
if (!mp_obj_is_type(uuid_obj, &bluetooth_uuid_type)) {
mp_raise_ValueError("invalid characteristic UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid characteristic UUID"));
}

(*handles)[handle_index++] = 0xffff;
Expand Down Expand Up @@ -487,7 +487,7 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
mp_obj_get_array_fixed_n(descriptor_obj, 2, &descriptor_items);
mp_obj_t desc_uuid_obj = descriptor_items[0];
if (!mp_obj_is_type(desc_uuid_obj, &bluetooth_uuid_type)) {
mp_raise_ValueError("invalid descriptor UUID");
mp_raise_ValueError(MP_ERROR_TEXT("invalid descriptor UUID"));
}

descriptor_uuids[descriptor_index] = MP_OBJ_TO_PTR(desc_uuid_obj);
Expand Down Expand Up @@ -567,7 +567,7 @@ STATIC mp_obj_t bluetooth_ble_gap_connect(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo = {0};
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
if (bufinfo.len != 6) {
mp_raise_ValueError("invalid addr");
mp_raise_ValueError(MP_ERROR_TEXT("invalid addr"));
}
mp_int_t scan_duration_ms = MP_BLUETOOTH_CONNECT_DEFAULT_SCAN_DURATION_MS;
if (n_args == 4) {
Expand Down
2 changes: 1 addition & 1 deletion extmod/modframebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
case FRAMEBUF_GS8:
break;
default:
mp_raise_ValueError("invalid format");
mp_raise_ValueError(MP_ERROR_TEXT("invalid format"));
}

return MP_OBJ_FROM_PTR(o);
Expand Down
6 changes: 3 additions & 3 deletions extmod/modlwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw,

ip_addr_t iplocal, ipremote;
if (!ipaddr_aton(mp_obj_str_get_str(args[1]), &iplocal)) {
mp_raise_ValueError("not a valid local IP");
mp_raise_ValueError(MP_ERROR_TEXT("not a valid local IP"));
}
if (!ipaddr_aton(mp_obj_str_get_str(args[2]), &ipremote)) {
mp_raise_ValueError("not a valid remote IP");
mp_raise_ValueError(MP_ERROR_TEXT("not a valid remote IP"));
}

struct netif *n = &lwip_slip_obj.lwip_netif;
if (netif_add(n, &iplocal, IP_ADDR_BROADCAST, &ipremote, NULL, slipif_init, ip_input) == NULL) {
mp_raise_ValueError("out of memory");
mp_raise_ValueError(MP_ERROR_TEXT("out of memory"));
}
netif_set_up(n);
netif_set_default(n);
Expand Down
4 changes: 2 additions & 2 deletions extmod/moduasyncio.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ STATIC mp_obj_t task_queue_pop_head(mp_obj_t self_in) {
mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_task_t *head = (mp_obj_task_t *)mp_pairheap_peek(task_lt, &self->heap->pairheap);
if (head == NULL) {
mp_raise_msg(&mp_type_IndexError, "empty heap");
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap"));
}
self->heap = (mp_obj_task_t *)mp_pairheap_pop(task_lt, &self->heap->pairheap);
return MP_OBJ_FROM_PTR(head);
Expand Down Expand Up @@ -173,7 +173,7 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) {
// Can't cancel self (not supported yet).
mp_obj_t cur_task = mp_obj_dict_get(uasyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task));
if (self_in == cur_task) {
mp_raise_msg(&mp_type_RuntimeError, "cannot cancel self");
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("cannot cancel self"));
}
// If Task waits on another task then forward the cancel to the one it's waiting on.
while (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(mp_obj_get_type(self->data)), MP_OBJ_FROM_PTR(&task_type))) {
Expand Down
6 changes: 3 additions & 3 deletions extmod/modubinascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ STATIC mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);

if ((bufinfo.len & 1) != 0) {
mp_raise_ValueError("odd-length string");
mp_raise_ValueError(MP_ERROR_TEXT("odd-length string"));
}
vstr_t vstr;
vstr_init_len(&vstr, bufinfo.len / 2);
Expand All @@ -90,7 +90,7 @@ STATIC mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
if (unichar_isxdigit(hex_ch)) {
hex_byte += unichar_xdigit_value(hex_ch);
} else {
mp_raise_ValueError("non-hex digit found");
mp_raise_ValueError(MP_ERROR_TEXT("non-hex digit found"));
}
if (i & 1) {
hex_byte <<= 4;
Expand Down Expand Up @@ -158,7 +158,7 @@ STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) {
}

if (nbits) {
mp_raise_ValueError("incorrect padding");
mp_raise_ValueError(MP_ERROR_TEXT("incorrect padding"));
}

return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
Expand Down
14 changes: 7 additions & 7 deletions extmod/moducryptolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
break;

default:
mp_raise_ValueError("mode");
mp_raise_ValueError(MP_ERROR_TEXT("mode"));
}

mp_obj_aes_t *o = m_new_obj_var(mp_obj_aes_t, struct ctr_params, !!is_ctr_mode(block_mode));
Expand All @@ -237,7 +237,7 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
mp_buffer_info_t keyinfo;
mp_get_buffer_raise(args[0], &keyinfo, MP_BUFFER_READ);
if (32 != keyinfo.len && 16 != keyinfo.len) {
mp_raise_ValueError("key");
mp_raise_ValueError(MP_ERROR_TEXT("key"));
}

mp_buffer_info_t ivinfo;
Expand All @@ -246,10 +246,10 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
mp_get_buffer_raise(args[2], &ivinfo, MP_BUFFER_READ);

if (16 != ivinfo.len) {
mp_raise_ValueError("IV");
mp_raise_ValueError(MP_ERROR_TEXT("IV"));
}
} else if (o->block_mode == UCRYPTOLIB_MODE_CBC || is_ctr_mode(o->block_mode)) {
mp_raise_ValueError("IV");
mp_raise_ValueError(MP_ERROR_TEXT("IV"));
}

if (is_ctr_mode(block_mode)) {
Expand All @@ -274,7 +274,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
mp_get_buffer_raise(in_buf, &in_bufinfo, MP_BUFFER_READ);

if (!is_ctr_mode(self->block_mode) && in_bufinfo.len % 16 != 0) {
mp_raise_ValueError("blksize % 16");
mp_raise_ValueError(MP_ERROR_TEXT("blksize % 16"));
}

vstr_t vstr;
Expand All @@ -284,7 +284,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
if (out_buf != MP_OBJ_NULL) {
mp_get_buffer_raise(out_buf, &out_bufinfo, MP_BUFFER_WRITE);
if (out_bufinfo.len < in_bufinfo.len) {
mp_raise_ValueError("output too small");
mp_raise_ValueError(MP_ERROR_TEXT("output too small"));
}
out_buf_ptr = out_bufinfo.buf;
} else {
Expand All @@ -301,7 +301,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
if ((encrypt && self->key_type == AES_KEYTYPE_DEC) ||
(!encrypt && self->key_type == AES_KEYTYPE_ENC)) {

mp_raise_ValueError("can't encrypt & decrypt");
mp_raise_ValueError(MP_ERROR_TEXT("can't encrypt & decrypt"));
}
}

Expand Down
Loading

0 comments on commit 4720e5e

Please sign in to comment.