Skip to content

bug: Commands exit with code 0 when they fail, and show incorrect error text #2

Closed

Description

@nabil1440

Blocker: yes. Fix this before the server-monitoring work starts.

Defect

  • Most commands use Run. They show the error, but the process exits with code 0.
  • Test: fly exec -- php sh -c 'exit 7' with Docker Compose v5.1.1. Result: the CLI shows Error executing command: exit status 7 and exits with code 0.
  • The exit codes are not consistent. base start and logs exit with code 1 when they fail. start, stop, restart, wp, exec, base stop, base restart, sites * and update exit with code 0.
  • Eight calls give err to color.Red without a format verb. color.Red uses a printf format. Thus, the output shows %!(EXTRA *exec.ExitError=exit status 1).
    • Locations: cmd/base.go:41,53,57,61 and cmd/site.go:43,60,80,84.
    • go vet does not find this defect.
  • base stop and base restart show "…successfully" after they show an error.
  • The CLI sends errors to stdout, not to stderr. Thus, errors mix with the output in a pipe, for example fly wp … | jq.
  • If a user who is not root runs fly update, the CLI shows an error and exits with code 0.

Cost

  • Scripts and automation cannot identify a failure.
  • The control plane and the event emitter will not get a correct result from each operation.
  • New capabilities will copy the current error pattern. The Cursor rules on main tell AI tools to use this pattern.
  • Users see incorrect text and incorrect success messages. This decreases their trust in the tool.

Benefit of the fix

  • Each command gives a correct exit code. Scripts, the control plane and the event emitter can use this code.
  • The CLI gives the exit code of the container command to the caller without change.
  • Error messages are clear and go to stderr.
  • New capabilities start from a correct error pattern.

Fix

  1. Use RunE on each command.
  2. Set SilenceUsage: true on the root command. Show the error one time in Execute().
  3. Get the exit code from *exec.ExitError. Exit with the same code.
  4. Remove os.Exit from the command bodies.
  5. Send errors and warnings to stderr.

Completion checks

  • fly exec -- php sh -c 'exit 7'; echo $? shows 7.
  • Each command exits with a code that is not 0 when its Docker call fails.
  • No command shows a success message after a failure.
  • Errors go to stderr.
  • Regression tests use a fake docker script on PATH.

Activity

  1. self-assigned this
    on Sep 21, 2026
  2. added a commit that references this issue on Sep 22, 2026
    c535470
  3. changed the title [-]Commands exit with code 0 when they fail, and show incorrect error text[/-] [+]bug: Commands exit with code 0 when they fail, and show incorrect error text[/+] on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions