Exceptions with negative values #11859
-
I have a program running on a Pico W that makes calls to a webservice using urequests.get. Periodically I get exceptions. Most are ETIMEDOUT and EINPROGRESS. Occasionally I get: Any help on what this is? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
My understanding is that the - is a Micropython thing. Look up 104 and 110 |
Beta Was this translation helpful? Give feedback.
-
@garumble negative codes for OSError mean that the code is not an official "errno" value, and generally represents an error code passed directly from some underlying library or subsystem. For example, in the bluetooth module, a negative value is something that we received from the host stack (e.g. NimBLE) that we cannot map to an errno value. This code might make that clearer: STATIC int8_t ble_hs_err_to_errno_table[] = {
[BLE_HS_EAGAIN] = MP_EAGAIN,
[BLE_HS_EALREADY] = MP_EALREADY,
[BLE_HS_EINVAL] = MP_EINVAL,
[BLE_HS_ENOENT] = MP_ENOENT,
[BLE_HS_ENOMEM] = MP_ENOMEM,
[BLE_HS_ENOTCONN] = MP_ENOTCONN,
[BLE_HS_ENOTSUP] = MP_EOPNOTSUPP,
[BLE_HS_ETIMEOUT] = MP_ETIMEDOUT,
[BLE_HS_EDONE] = MP_EIO, // TODO: Maybe should be MP_EISCONN (connect uses this for "already connected").
[BLE_HS_EBUSY] = MP_EBUSY,
[BLE_HS_EBADDATA] = MP_EINVAL,
};
STATIC int ble_hs_err_to_errno(int err) {
DEBUG_printf("ble_hs_err_to_errno: %d\n", err);
if (!err) {
return 0;
}
if (err >= 0 && (unsigned)err < MP_ARRAY_SIZE(ble_hs_err_to_errno_table) && ble_hs_err_to_errno_table[err]) {
// Return an MP_Exxx error code.
return ble_hs_err_to_errno_table[err];
} else {
// Pass through the BLE error code.
return -err;
}
} |
Beta Was this translation helpful? Give feedback.
C (or cpp) deliver the negative values in the errno.h header file.
So it seems as if the (Python) library in question does not always convert the return values appropriately.
One can easily do that by multiplying with the negative Logarithmus Naturalis of the Euler constant.