Skip to content

Map asyncssh connect-call OS errors to user-facing validation errors - #51

Merged
gensyn merged 4 commits into
mainfrom
copilot/catch-generic-error-and-present-friendly-message
Sep 1, 2026
Merged

Map asyncssh connect-call OS errors to user-facing validation errors#51
gensyn merged 4 commits into
mainfrom
copilot/catch-generic-error-and-present-friendly-message

Conversation

Copilot AI commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

ssh_command.execute surfaced low-level asyncssh/socket tracebacks for failed TCP connects (e.g. OSError: [Errno 101] Connect call failed (...)), which appeared to users as generic script failures. This change maps those transport-level reachability errors into existing localized service errors.

  • Error handling (runtime behavior)

    • Extend SshCommandCoordinator.async_execute() OSError handling to treat unreachable-network host errors as host_not_reachable.
    • Specifically map errno values ENETUNREACH and EHOSTUNREACH (in addition to existing socket.gaierror) to ServiceValidationError with translation key host_not_reachable.
  • Coverage updates

    • Add unit coverage for OSError(101, "Connect call failed ...") to verify translation key mapping.
    • Add integration coverage for the same path through the Home Assistant service call boundary.
except OSError as exc:
    if isinstance(exc, socket.gaierror) or exc.errno in (ENETUNREACH, EHOSTUNREACH):
        raise ServiceValidationError(
            "Host is not reachable.",
            translation_domain=DOMAIN,
            translation_key="host_not_reachable",
        ) from exc
    raise

Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
@gensyn
gensyn marked this pull request as ready for review September 1, 2026 08:19
Copilot AI lite review requested due to automatic review settings September 1, 2026 08:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The newly added tests hard-code errno 101, which is platform-dependent; using ENETUNREACH (and/or EHOSTUNREACH) constants will make the coverage robust.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves ssh_command.execute error handling by converting specific transport-layer OSError failures from asyncssh.connect() (network/host unreachable) into a user-facing ServiceValidationError with the existing host_not_reachable translation key, and adds test coverage for that mapping.

Changes:

  • Map OSError with errno in (ENETUNREACH, EHOSTUNREACH) to ServiceValidationError(..., translation_key="host_not_reachable") (in addition to existing socket.gaierror handling).
  • Add unit test coverage for the new unreachable-network mapping.
  • Add integration test coverage for the same mapping through the Home Assistant service call boundary.
File summaries
File Description
coordinator.py Extends OSError handling to map unreachable network/host errors to host_not_reachable.
tests/unit_tests/test_coordinator.py Adds a unit test asserting translation key mapping for unreachable-network OSError.
tests/integration_tests/test_integration.py Adds an integration test asserting translation key mapping for unreachable-network OSError via service call.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/unit_tests/test_coordinator.py
Comment thread tests/integration_tests/test_integration.py
gensyn and others added 3 commits September 1, 2026 10:24
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@gensyn
gensyn merged commit f7171a3 into main Sep 1, 2026
5 checks passed
@gensyn
gensyn deleted the copilot/catch-generic-error-and-present-friendly-message branch September 1, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants