From 2bf5a947b2b01f2be6c7b05707391dd09b240ad0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 15 Jun 2017 12:02:14 +1000 Subject: [PATCH] stmhal: Make error messages more consistent across peripherals. --- stmhal/can.c | 6 +++--- stmhal/dac.c | 4 ++-- stmhal/i2c.c | 4 ++-- stmhal/lcd.c | 2 +- stmhal/led.c | 2 +- stmhal/machine_i2c.c | 4 ++-- stmhal/pin.c | 2 +- stmhal/servo.c | 2 +- stmhal/spi.c | 4 ++-- stmhal/timer.c | 4 ++-- stmhal/uart.c | 6 +++--- stmhal/wdt.c | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/stmhal/can.c b/stmhal/can.c index afc1b367f6..6152022b76 100644 --- a/stmhal/can.c +++ b/stmhal/can.c @@ -321,7 +321,7 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, mp_uint_t n_args, const // init CAN (if it fails, it's because the port doesn't exist) if (!can_init(self)) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN port %d does not exist", self->can_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%d) doesn't exist", self->can_id)); } return mp_const_none; @@ -357,13 +357,13 @@ STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_ can_idx = PYB_CAN_2; #endif } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%s) does not exist", port)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%s) doesn't exist", port)); } } else { can_idx = mp_obj_get_int(args[0]); } if (can_idx < 1 || can_idx > MP_ARRAY_SIZE(MP_STATE_PORT(pyb_can_obj_all))) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%d) does not exist", can_idx)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN(%d) doesn't exist", can_idx)); } pyb_can_obj_t *self; diff --git a/stmhal/dac.c b/stmhal/dac.c index 4ba37b135c..1c372f73c4 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -221,7 +221,7 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_ } else if (pin == &pin_A5) { dac_id = 2; } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %q does not have DAC capabilities", pin->name)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin(%q) doesn't have DAC capabilities", pin->name)); } } @@ -237,7 +237,7 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_ dac->dac_channel = DAC_CHANNEL_2; dac->tx_dma_descr = &dma_DAC_2_TX; } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "DAC %d does not exist", dac_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "DAC(%d) doesn't exist", dac_id)); } // configure the peripheral diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 4a792d1630..d0d877818a 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -626,14 +626,14 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_ #endif } else { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "I2C(%s) does not exist", port)); + "I2C(%s) doesn't exist", port)); } } else { i2c_id = mp_obj_get_int(args[0]); if (i2c_id < 1 || i2c_id > MP_ARRAY_SIZE(pyb_i2c_obj) || pyb_i2c_obj[i2c_id - 1].i2c == NULL) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "I2C(%d) does not exist", i2c_id)); + "I2C(%d) doesn't exist", i2c_id)); } } diff --git a/stmhal/lcd.c b/stmhal/lcd.c index da09744606..cdf9fa0d1a 100644 --- a/stmhal/lcd.c +++ b/stmhal/lcd.c @@ -220,7 +220,7 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_ lcd->pin_a0 = &pyb_pin_Y5; lcd->pin_bl = &pyb_pin_Y12; } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LCD bus '%s' does not exist", lcd_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LCD(%s) doesn't exist", lcd_id)); } // init the SPI bus diff --git a/stmhal/led.c b/stmhal/led.c index 4665146848..4b9895fc55 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -299,7 +299,7 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_ // check led number if (!(1 <= led_id && led_id <= NUM_LEDS)) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LED(%d) does not exist", led_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LED(%d) doesn't exist", led_id)); } // return static led object diff --git a/stmhal/machine_i2c.c b/stmhal/machine_i2c.c index aec53205f5..1be2151e3b 100644 --- a/stmhal/machine_i2c.c +++ b/stmhal/machine_i2c.c @@ -510,14 +510,14 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz #endif } else { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "I2C(%s) does not exist", port)); + "I2C(%s) doesn't exist", port)); } } else { i2c_id = mp_obj_get_int(args[ARG_id].u_obj); if (i2c_id < 1 || i2c_id > MP_ARRAY_SIZE(machine_hard_i2c_obj) || machine_hard_i2c_obj[i2c_id - 1].base.type == NULL) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "I2C(%d) does not exist", i2c_id)); + "I2C(%d) doesn't exist", i2c_id)); } } diff --git a/stmhal/pin.c b/stmhal/pin.c index db75969007..4c0d49e7d3 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -176,7 +176,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) { return pin_obj; } - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin '%s' not a valid pin identifier", mp_obj_str_get_str(user_obj))); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin(%s) doesn't exist", mp_obj_str_get_str(user_obj))); } /// \method __str__() diff --git a/stmhal/servo.c b/stmhal/servo.c index 4c62044dd9..1f1aa5a2d2 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -194,7 +194,7 @@ STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, siz // check servo number if (!(0 <= servo_id && servo_id < PYB_SERVO_NUM)) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id + 1)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo(%d) doesn't exist", servo_id + 1)); } // get and init servo object diff --git a/stmhal/spi.c b/stmhal/spi.c index eb7edbea06..b710fc3a7c 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -182,7 +182,7 @@ STATIC int spi_find(mp_obj_t id) { #endif } nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "SPI(%s) does not exist", port)); + "SPI(%s) doesn't exist", port)); } else { // given an integer id int spi_id = mp_obj_get_int(id); @@ -191,7 +191,7 @@ STATIC int spi_find(mp_obj_t id) { return spi_id; } nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "SPI(%d) does not exist", spi_id)); + "SPI(%d) doesn't exist", spi_id)); } } diff --git a/stmhal/timer.c b/stmhal/timer.c index fd0695bdd2..64d445111a 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -702,7 +702,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz #if defined(TIM17) case 17: tim->tim.Instance = TIM17; tim->irqn = TIM1_TRG_COM_TIM17_IRQn; break; #endif - default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer %d does not exist", tim->tim_id)); + default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer(%d) doesn't exist", tim->tim_id)); } // set the global variable for interrupt callbacks @@ -896,7 +896,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp const pin_obj_t *pin = pin_obj; const pin_af_obj_t *af = pin_find_af(pin, AF_FN_TIM, self->tim_id); if (af == NULL) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %q doesn't have an af for TIM%d", pin->name, self->tim_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin(%q) doesn't have an af for Timer(%d)", pin->name, self->tim_id)); } // pin.init(mode=AF_PP, af=idx) const mp_obj_t args2[6] = { diff --git a/stmhal/uart.c b/stmhal/uart.c index 2d67411b1f..735c6f168b 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -615,7 +615,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con // init UART (if it fails, it's because the port doesn't exist) if (!uart_init2(self)) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) does not exist", self->uart_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) doesn't exist", self->uart_id)); } // set timeout @@ -751,12 +751,12 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size uart_id = PYB_UART_6; #endif } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) does not exist", port)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) doesn't exist", port)); } } else { uart_id = mp_obj_get_int(args[0]); if (!uart_exists(uart_id)) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) does not exist", uart_id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) doesn't exist", uart_id)); } } diff --git a/stmhal/wdt.c b/stmhal/wdt.c index af2481e926..272c575ef5 100644 --- a/stmhal/wdt.c +++ b/stmhal/wdt.c @@ -49,7 +49,7 @@ STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_ mp_int_t id = args[ARG_id].u_int; if (id != 0) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "WDT(%d) does not exist", id)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "WDT(%d) doesn't exist", id)); } // timeout is in milliseconds