Skip to content

spawn launch: exit code 0 on launch failure — makes scripting unreliable #16

Closed

Description

@scttfrdmn

Summary

spawn launch returns exit code 0 even when the launch fails. This makes it impossible to detect failure in scripts via $? or subprocess.returncode.

Steps to reproduce

spawn launch test --instance-type t4g.small --ami auto -y
echo "exit: $?"   # prints "exit: 0" despite the error

Output includes failed to launch instance: ... on stderr/stdout but the process exits 0.

Expected

Non-zero exit code on any launch failure so that scripts can reliably detect and handle errors:

if ! spawn launch ...; then
    echo "Launch failed"
    exit 1
fi

Impact

Callers using subprocess.run(..., check=False) and checking returncode != 0 will silently proceed as if the launch succeeded, then fail later when trying to parse the instance ID from empty/error output.

Context

https://github.com/scttfrdmn/aws-microbiome-demo — discovered when our Python wrapper checked result.returncode != 0 and never caught the failure.

Activity

  1. added
    bug
    on May 30, 2026
  2. scttfrdmn commented on May 31, 2026

    @scttfrdmn
    ContributorAuthor

    Investigated — could not reproduce exit 0; spawn appears to exit 1 correctly

    I tried to reproduce this and, measured directly, spawn launch (and other commands) do exit non-zero on failure:

    $ AWS_ACCESS_KEY_ID=bad AWS_SECRET_ACCESS_KEY=bad spawn launch testx \
        --instance-type t4g.small --ami ami-0 --region us-east-1 -y 2>/tmp/err
    $ echo $?
    1
    

    Traced the path: every launch path returns its error to RunE → rootCmd.Execute() returns it (confirmed with an instrumented build) → Execute() runs os.Exit(1). extend and other RunE commands behave the same (exit 1 on error).

    One likely explanation for the original observation: a shell pipe can mask the exit code. $? reflects the last command in a pipeline, so:

    spawn launch ... | tail        # $? is tail's (0), NOT spawn's
    spawn launch ...; echo $?      # this correctly shows spawn's exit code

    I hit exactly this myself while investigating. If your wrapper captured output through a pipe (or tee), $?/returncode could read the wrong process. With subprocess.run([...], capture_output=True) (no shell pipe), returncode should be accurate.

    The other factor: your repro used --ami auto, which failed due to #15 (now fixed in #17). With that fix, --ami auto no longer errors at all — so that specific command will now succeed rather than testing the failure path.

    What I need to confirm a real bug

    If you still see exit 0 on a genuine failure, please paste:

    1. The exact command (no pipe), and echo $? on the very next line.
    2. Whether it's via shell or subprocess (and the exact subprocess call).

    Holding this open pending that — happy to fix immediately if there's a path I missed, but I don't want to ship a speculative change to error handling that already appears correct.

  3. scttfrdmn commented on Jun 25, 2026

    @scttfrdmn
    ContributorAuthor

    Already fixed on main — verified

    spawn launch now returns a non-zero exit code on launch failure. runLaunch is a cobra RunE that returns the error, and cmd.Execute() does os.Exit(1) on a non-nil error (cmd/root.go:49-52, with SilenceErrors: true so the error prints once). Verified live against main (built from HEAD) across several failure modes:

    Scenario Exit
    RunInstances failure (bad AMI id) 1
    bad instance type (InvalidParameterValue) 1
    missing required --name arg 1
    AMI auto-resolve failure (bogus region) 1

    Example:

    $ spawn launch testexit --instance-type t4g.small --ami ami-000... --no-detach --ttl 1h -y; echo $?
    ...
    failed to launch instance: InvalidAMIID.Malformed: ...
    1
    

    (The original report predates the cobra RunE/Execute exit wiring.) Closing as resolved; reopen if a specific path still exits 0 — happy to add a regression test if you'd like one pinned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions