Skip to content

Make the "name or service not known" message translatable #7382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
4 changes: 2 additions & 2 deletions ports/espressif/common-hal/socketpool/Socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/common-hal/socketpool/SocketPool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
17 changes: 11 additions & 6 deletions shared-bindings/socketpool/SocketPool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
2 changes: 1 addition & 1 deletion shared-bindings/socketpool/SocketPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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