1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-05-19 06:08:51 +01:00
Files
supervisor/tests/host
Stefan Agner 9923b8580b Return proper API errors for invalid hostnames (#6776)
Follow-up on #6739: with HassioError now logged and captured by Sentry
in api_process, hostname rejections from systemd-hostnamed surfaced as
"unexpected" 400s with noisy log entries and a Sentry event, even
though the user had simply submitted an invalid hostname.

Map this through properly so the API returns a clean, structured 400:

- Split ErrorType.INVALID_ARGS out of DBusInterfaceMethodError into its
  own DBusInvalidArgsError. The two cases collapsed there before are
  semantically different: UNKNOWN_METHOD / INVALID_SIGNATURE mean the
  call is broken (method missing or types wrong); INVALID_ARGS means
  the call is valid but the service rejected an argument's value.
- Add HostInvalidHostnameError(HostError, APIError) with error_key and
  extra_fields so clients get a normalized message and a stable key
  rather than systemd's raw "Invalid static hostname '...'" text.
- Translate DBusInvalidArgsError to HostInvalidHostnameError in
  SystemControl.set_hostname. @api_process turns the result into a 400
  without logging or Sentry capture, since this is now a modeled
  client-input error rather than an unexpected one.

Validation continues to live in hostnamed (hostname_is_valid() in
systemd's src/basic/hostname-util.c); Supervisor only translates the
rejection.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 10:19:27 +02:00
..