Skip to content

fix(tools): catch URLError in latestVersion and listAMIs - #691

Draft
deepak0x wants to merge 1 commit into
flatcar:mainfrom
deepak0x:fix/fcl-fetch-urlerror
Draft

fix(tools): catch URLError in latestVersion and listAMIs#691
deepak0x wants to merge 1 commit into
flatcar:mainfrom
deepak0x:fix/fcl-fetch-urlerror

Conversation

@deepak0x

@deepak0x deepak0x commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Network-level failures (DNS, timeout, connection refused) raise urllib.error.URLError, which is not a subclass of HTTPError and was therefore uncaught. The exception propagated through main() and crashed the script before any output file was written.

Changes

  • Import URLError and catch it in latestVersion() and listAMIs(), raising a clear RuntimeError with the underlying reason (e.reason).
  • Add a timeout=30 to urlopen so unreachable hosts fail deterministically instead of hanging indefinitely.
  • Add unit tests covering: success, 404 fallback, non-404 HTTPError propagation, and URLError -> RuntimeError (7/7 passing).

Verification

python3 tools/test_fcl_fetch_version_data.py
.......
Ran 7 tests in 0.005s
OK

Fixes flatcar/Flatcar#2364.

Note: this edits tools/fcl-fetch-version-data.py, the same file as the open PR #688 (flatcar flatcar/Flatcar#2365, which fixed the silent None return). The two are independent fixes; one will need a rebase after the other merges to resolve the overlapping except block. Happy to rebase on request.

Network-level failures (DNS, timeout, connection refused) raise
urllib.error.URLError, which is not a subclass of HTTPError and was
therefore uncaught, crashing the script before any output was written.

Catch URLError in latestVersion() and listAMIs() and raise a clear
RuntimeError with the underlying reason. Also set a 30s timeout on
urlopen so unreachable hosts fail deterministically instead of hanging.

Fixes flatcar/flatcar-website#690

Signed-off-by: Deepak Bhagat <deepak0x@users.noreply.github.com>
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.

bug: URLError not caught in latestVersion, crashes on network failure

1 participant