Skip to content

Handle network errors gracefully during downloads#416

Open
Rani367 wants to merge 1 commit intoAsahiLinux:mainfrom
Rani367:fix-network-error-handling
Open

Handle network errors gracefully during downloads#416
Rani367 wants to merge 1 commit intoAsahiLinux:mainfrom
Rani367:fix-network-error-handling

Conversation

@Rani367
Copy link
Copy Markdown

@Rani367 Rani367 commented Mar 13, 2026

Summary

Closes #409.

When internet connectivity is lost during downloads, the installer crashes with a raw Python traceback. This patch catches network exceptions and shows actionable error messages with recovery guidance instead.

Changes in urlcache.py:

  • Add NetworkError exception class
  • Add retry logic to get_size(), which previously had no retries at all (network errors during the initial HEAD request would crash immediately)
  • get_block() now raises NetworkError after retries are exhausted instead of re-raising the raw exception

Changes in main.py:

  • Wrap pre-partition download calls (load_ipsw, load_package) with interactive retry prompts, since no disk changes have been made at that point and retrying is safe
  • Wrap post-partition do_install() calls with a clean exit message that tells the user to re-run the installer for automatic repair
  • Add NetworkError handler to action_rebuild_vendorfw
  • Add NetworkError catch in the global exception handler as a safety net

Before (raw traceback, no guidance):

Traceback (most recent call last):
  File "main.py", line ...
    ...
ConnectionResetError: [Errno 54] Connection reset by peer

After:

Pre-partition failure (interactive retry):

Download failed: Failed to connect to cdn.example.com after multiple retries
Please check your internet connection.
>> Retry (y/N):

Post-partition failure (clean exit with repair guidance):

Installation failed due to a network error.
  Download failed: lost connection to cdn.example.com

Please check your internet connection, then re-run the installer.
The installer will detect the incomplete installation and offer
to repair it.

Test plan

  • NetworkError class imports correctly and is a proper Exception subclass
  • get_size() retries 5 times with backoff on connection failure, then raises NetworkError
  • get_block() retries 10 times (unchanged), then raises NetworkError instead of raw exception
  • Exception chaining (from e) preserves original traceback in logs
  • Both files pass py_compile syntax check
  • Full install with stable network works unaffected (happy path)
  • Kill network before partition creation, get retry prompt, restore network, retry succeeds
  • Kill network after partition creation, get clean exit, re-run installer, repair offered

When internet connectivity is lost during downloads, the installer now
catches network exceptions and shows user-friendly error messages with
recovery guidance instead of crashing with a Python traceback.

- Add NetworkError exception class to urlcache.py
- Add retry logic to get_size() which previously had none (5 retries
  with backoff)
- Raise NetworkError from get_block() after retries exhausted instead
  of re-raising raw exceptions
- Wrap pre-partition download calls with interactive retry prompts
  (safe to retry since no disk state has changed)
- Wrap post-partition do_install() calls with clean exit and repair
  guidance (tells user to re-run installer to trigger repair flow)
- Add NetworkError handler to action_rebuild_vendorfw
- Add NetworkError safety net in global exception handler

Closes AsahiLinux#409

Signed-off-by: Rani367 <rani2011367@gmail.com>
@Rani367 Rani367 force-pushed the fix-network-error-handling branch from 049c8c9 to f09f031 Compare March 13, 2026 21:54
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.

Install Script - Uncaught Python exception if internet connectivity is lost during download

1 participant