fix(connection): re-raise OSError on initial connect so failures are reported#213
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #213 +/- ##
=======================================
Coverage 86.43% 86.43%
=======================================
Files 159 159
Lines 8831 8832 +1
=======================================
+ Hits 7633 7634 +1
Misses 1198 1198 ☔ View full report in Codecov by Harness. |
6c51c87 to
a6e1751
Compare
…reported connect()'s OSError branch logged but did not re-raise when quiet=False. Since __init__ always calls connect(quiet=False), an unreachable host (refused / timed out / no route) produced a Connection with a dead transport that __init__ returned successfully. Target.connect's 'except Exception -> ConnectingTargetFailed' handler only wraps the constructor, so execution fell through to is_locked() and parse_system() on the dead transport and crashed with an opaque low-level error. Re-raise in the non-quiet OSError branch so Target.connect reports the clean ConnectingTargetFailedMessage and aborts cleanly. The quiet=True reconnect path (host rebooting) still swallows it; reconnect()'s is_active() loop decides when to give up, unchanged. Updates the previously-pinning test to assert the initial connect now raises, and adds a Target.connect test asserting ConnectingTargetFailedMessage is logged and the error re-raised.
a6e1751 to
0725830
Compare
mimi1vx
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Connection.connect()'sOSErrorbranch logged the failure but did notre-raise when
quiet=False:__init__always callsconnect(quiet=False), so an unreachable host(connection refused / timed out / no route) yielded a
Connectionwith a deadtransport that
__init__returned successfully.Target.connectwraps onlythe constructor in its
except Exception -> ConnectingTargetFailedMessagehandler, so control then fell through to
is_locked()andparse_system(self.connection)running against the dead transport — crashingwith an opaque low-level error instead of the intended
"connecting to failed: ".
(Auth failures and generic
SSHExceptionalready re-raise; only the plainnetwork
OSErrorwas swallowed.)Fix
Re-raise in the non-quiet
OSErrorbranch. Thequiet=Truereconnect path(host rebooting) still swallows it and lets
reconnect()'sis_active()loopdecide when to give up — unchanged.
Tests
test_connect_oserror_is_logged_not_raisedis updated(now
..._is_logged_and_raised) to assert the initial connect raises whilestill logging "No valid connection".
test_connect_failure_surfaces_connecting_failed_message(target) assertsTarget.connectlogsConnectingTargetFailedMessageand re-raises when theconnection fails.
quiet=Trueswallow test is unaffected and still passes.Gates: ruff format/check clean, ty clean, pytest green (126 connection+target).
🤖 Generated with Claude Code