Skip to content

fix(connection): re-raise OSError on initial connect so failures are reported#213

Merged
mimi1vx merged 1 commit into
openSUSE:mainfrom
plusky:fix/connect-oserror-reraise
Jun 23, 2026
Merged

fix(connection): re-raise OSError on initial connect so failures are reported#213
mimi1vx merged 1 commit into
openSUSE:mainfrom
plusky:fix/connect-oserror-reraise

Conversation

@plusky

@plusky plusky commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Problem

Connection.connect()'s OSError branch logged the failure but did not
re-raise when quiet=False:

except OSError:
    if quiet:
        logger.debug("No valid connection to %s:%s (yet)", ...)
    else:
        logger.error("No valid connection to %s:%s", ...)   # falls through

__init__ always calls connect(quiet=False), so an unreachable host
(connection refused / timed out / no route) yielded a Connection with a dead
transport that __init__ returned successfully. Target.connect wraps only
the constructor in its except Exception -> ConnectingTargetFailedMessage
handler, so control then fell through to is_locked() and
parse_system(self.connection) running against the dead transport — crashing
with an opaque low-level error instead of the intended
"connecting to failed: ".

(Auth failures and generic SSHException already re-raise; only the plain
network OSError was swallowed.)

Fix

Re-raise in the non-quiet OSError branch. The quiet=True reconnect path
(host rebooting) still swallows it and lets reconnect()'s is_active() loop
decide when to give up — unchanged.

Tests

  • The previously-pinning test_connect_oserror_is_logged_not_raised is updated
    (now ..._is_logged_and_raised) to assert the initial connect raises while
    still logging "No valid connection".
  • New test_connect_failure_surfaces_connecting_failed_message (target) asserts
    Target.connect logs ConnectingTargetFailedMessage and re-raises when the
    connection fails.
  • The quiet=True swallow test is unaffected and still passes.

Gates: ruff format/check clean, ty clean, pytest green (126 connection+target).

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.43%. Comparing base (1d8dd6b) to head (0725830).

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.
📢 Have feedback on the report? Share it here.

@plusky plusky force-pushed the fix/connect-oserror-reraise branch 2 times, most recently from 6c51c87 to a6e1751 Compare June 22, 2026 08:26
…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.
@plusky plusky force-pushed the fix/connect-oserror-reraise branch from a6e1751 to 0725830 Compare June 23, 2026 08:44
@mimi1vx mimi1vx merged commit d591e8f into openSUSE:main Jun 23, 2026
6 checks passed
@plusky plusky deleted the fix/connect-oserror-reraise branch June 23, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants