diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 0cf1027239..17c39cafdc 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1393,6 +1393,10 @@ msgstr "" msgid "NVS Error" msgstr "" +#: shared-bindings/socketpool/SocketPool.c +msgid "Name or service not known" +msgstr "" + #: py/qstr.c msgid "Name too long" msgstr "" diff --git a/ports/espressif/common-hal/socketpool/Socket.c b/ports/espressif/common-hal/socketpool/Socket.c index 18237a4d4e..ccb01116d8 100644 --- a/ports/espressif/common-hal/socketpool/Socket.c +++ b/ports/espressif/common-hal/socketpool/Socket.c @@ -369,7 +369,7 @@ void common_hal_socketpool_socket_connect(socketpool_socket_obj_t *self, struct addrinfo *result_i; int error = lwip_getaddrinfo(host, NULL, &hints, &result_i); if (error != 0 || result_i == NULL) { - common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known); + common_hal_socketpool_socketpool_raise_gaierror_noname(); } // Set parameters @@ -550,7 +550,7 @@ mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t *self, struct addrinfo *result_i; int error = lwip_getaddrinfo(host, NULL, &hints, &result_i); if (error != 0 || result_i == NULL) { - common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known); + common_hal_socketpool_socketpool_raise_gaierror_noname(); } // Set parameters diff --git a/ports/raspberrypi/common-hal/socketpool/SocketPool.c b/ports/raspberrypi/common-hal/socketpool/SocketPool.c index bdbc7f67c5..e562314d69 100644 --- a/ports/raspberrypi/common-hal/socketpool/SocketPool.c +++ b/ports/raspberrypi/common-hal/socketpool/SocketPool.c @@ -98,7 +98,7 @@ void socketpool_resolve_host_raise(socketpool_socketpool_obj_t *self, const char int result = socketpool_resolve_host(self, host, addr); if (result < 0) { printf("socket_resolve_host() returned %d\n", result); - common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known); + common_hal_socketpool_socketpool_raise_gaierror_noname(); mp_raise_OSError(-result); } } diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index 660aba63ed..f056c741f3 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -198,16 +198,21 @@ MP_WEAK mp_obj_t common_hal_socketpool_socketpool_gethostbyname_raise(socketpool_socketpool_obj_t *self, const char *host) { mp_obj_t ip_str = common_hal_socketpool_socketpool_gethostbyname(self, host); if (ip_str == mp_const_none) { - common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known); + common_hal_socketpool_socketpool_raise_gaierror_noname(); } return ip_str; } MP_WEAK NORETURN -void common_hal_socketpool_socketpool_raise_gaierror(int value, qstr name) { - mp_obj_t exc_args[2] = { - MP_OBJ_NEW_SMALL_INT(value), - MP_OBJ_NEW_QSTR(name), +void common_hal_socketpool_socketpool_raise_gaierror_noname(void) { + vstr_t vstr; + mp_print_t print; + vstr_init_print(&vstr, 64, &print); + mp_printf(&print, "%S", translate("Name or service not known")); + + mp_obj_t exc_args[] = { + MP_OBJ_NEW_SMALL_INT(SOCKETPOOL_EAI_NONAME), + mp_obj_new_str_from_vstr(&mp_type_str, &vstr), }; - nlr_raise(mp_obj_new_exception_args(&mp_type_gaierror, 2, exc_args)); + nlr_raise(mp_obj_new_exception_args(&mp_type_gaierror, MP_ARRAY_SIZE(exc_args), exc_args)); } diff --git a/shared-bindings/socketpool/SocketPool.h b/shared-bindings/socketpool/SocketPool.h index cecbdd86f1..6409f8c763 100644 --- a/shared-bindings/socketpool/SocketPool.h +++ b/shared-bindings/socketpool/SocketPool.h @@ -73,6 +73,6 @@ bool socketpool_socket(socketpool_socketpool_obj_t *self, socketpool_socketpool_addressfamily_t family, socketpool_socketpool_sock_t type, socketpool_socket_obj_t *sock); -NORETURN void common_hal_socketpool_socketpool_raise_gaierror(int value, qstr name); +NORETURN void common_hal_socketpool_socketpool_raise_gaierror_noname(void); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_SOCKETPOOL_SOCKETPOOL_H