Skip to content

fix(cli): return correct exit codes and report errors on stderr - #18

Merged
nabil1440 merged 2 commits into
blockers/6-go-toolchainfrom
blockers/2-exit-codes
Sep 22, 2026
Merged

nabil1440 merged 2 commits into
blockers/6-go-toolchainfrom
blockers/2-exit-codes

Conversation

@nabil1440

@nabil1440 nabil1440 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Change

  • Each command uses RunE. Execute shows the error one time and sets the exit status.
  • When docker compose or wp-cli fails, fly exits with the same status and shows no more text. For example, wp plugin is-installed keeps its exit status.
  • Other errors go to stderr as Error: … with exit status 1. Usage errors also show Run 'fly <command> --help' for usage.
  • This PR removes the 8 color.Red("…:", err) calls. They showed %!(EXTRA …).
  • Success messages show only after success.
  • sites start, sites stop and sites restart continue after a failed site. At the end, they show each failed site. One function replaces the two copies of this code.
  • Each failure line starts with its phase, for example stopping example.com: exit status 1. Thus sites restart shows two different lines when a site fails to stop and then fails to start.
  • fly exec without arguments and fly update without root give exit status 1.
  • internal/testutil adds a fake docker script for tests. main_test.go builds fly and runs it end to end.

Behavior change

  • Scripts that call fly now get a correct exit status. Before this change, most failures gave exit status 0.

Tests

  • Unit tests: exitCode, forEachSite, and sites restart with a site that fails in the two phases.
  • End-to-end tests with the fake docker:
    • A child exit status of 7 gives a fly exit status of 7.
    • Ten Docker commands exit with the child status 3 and show no success message.
    • The no-site error goes to stderr.
    • Usage errors give exit status 1.
  • The same end-to-end tests fail on the code before this PR.
  • Real Docker (Compose v5.1.1): fly exec -- php sh -c 'exit 7' exits with status 7.

Closes #2

- Use RunE on every command and let Execute report the error once.
- Pass the exit status of docker compose and wp-cli through unchanged.
- Print other errors on stderr with a non-zero exit status.
- Remove the color.Red printf misuse that printed %!(EXTRA ...).
- Show success messages only after success.
- sites start/stop/restart continue after a failed site and report
  every failed site.
- Add a fake docker test harness and end-to-end tests.

Closes #2
@nabil1440
nabil1440 added this pull request to stack #24 September 21, 2026 10:41
sites restart printed 'site: exit status 1' twice when a site failed
to stop and then to start. Each failure now starts with its phase:
'stopping site: …' or 'starting site: …'.

Part of #2
@nabil1440
nabil1440 merged commit c535470 into develop Sep 22, 2026
@nabil1440
nabil1440 deleted the blockers/2-exit-codes branch September 22, 2026 06:51
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: Commands exit with code 0 when they fail, and show incorrect error text

1 participant