Skip to content

fix(upgrade): exit non-zero with clear error when download fails#659

Merged
Chemaclass merged 1 commit intomainfrom
fix/upgrade-fail-silent
May 4, 2026
Merged

fix(upgrade): exit non-zero with clear error when download fails#659
Chemaclass merged 1 commit intomainfrom
fix/upgrade-fail-silent

Conversation

@Chemaclass
Copy link
Copy Markdown
Member

Summary

bashunit upgrade reported success even when the binary download failed, leaving users on the old version without any clue what went wrong:

> bashunit upgrade
> Upgrading bashunit to latest version
Failed to download bashunit
> bashunit upgraded successfully to latest version 0.35.0
$ bashunit -v
bashunit - 0.34.1

This PR makes the command behave correctly and tells the user why it failed.

Behavior changes

  • Aborts on download failure with a non-zero exit code (no more false success message).
  • Prints the exact URL it tried and the underlying curl/wget stderr (e.g. curl: (6) Could not resolve host).
  • Validates the downloaded file is non-empty before chmod, so a zero-byte response from a CDN/proxy does not silently overwrite the binary.
  • Emits a clear error when the latest tag cannot be resolved (no internet / no git).
  • Accepts BASHUNIT_INSTALL_DIR for testability and uses an absolute target path instead of cd-ing into src/.
  • bashunit::io::download_to switches curl to -fsSL so HTTP errors (404/5xx) become real failures, and lets stderr through so the caller can surface it.

Files

  • src/upgrade.sh — fixed control flow, error reporting, env-overridable install dir
  • src/io.shcurl -fsSL, stderr no longer swallowed, dependency miss message
  • tests/unit/upgrade_test.sh — new unit tests covering all failure paths
  • CHANGELOG.md — Unreleased entry

Test plan

  • ./bashunit tests/unit/upgrade_test.sh — 6 passing (download fail, error message surfacing, empty file, missing tag, success path, already-on-latest)
  • ./bashunit tests/ — full suite green
  • make sa (ShellCheck)
  • make lint (EditorConfig)
  • Pre-commit hook (full suite + static analysis) passes

Previously `bashunit upgrade` printed "upgraded successfully" even when
the curl/wget download failed, leaving users on the old version with
no indication of what went wrong.

Now the command:
- aborts immediately on download failure and returns a non-zero exit code
- prints the URL it tried plus the underlying curl/wget stderr
- guards against empty downloads (zero-byte files no longer overwrite the binary)
- reports a clear error when the latest tag cannot be resolved
- accepts BASHUNIT_INSTALL_DIR for testability
@Chemaclass Chemaclass enabled auto-merge (squash) May 4, 2026 06:33
@Chemaclass Chemaclass merged commit 56b8481 into main May 4, 2026
30 checks passed
@Chemaclass Chemaclass deleted the fix/upgrade-fail-silent branch May 4, 2026 06:34
@Chemaclass Chemaclass self-assigned this May 4, 2026
@Chemaclass Chemaclass added the bug Something isn't working label May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant