Skip to content

fix(compose): return nil error on non-zero container exit codes#13874

Closed
vmphase wants to merge 2 commits into
docker:mainfrom
vmphase:fix/exec-nil-error
Closed

fix(compose): return nil error on non-zero container exit codes#13874
vmphase wants to merge 2 commits into
docker:mainfrom
vmphase:fix/exec-nil-error

Conversation

@vmphase

@vmphase vmphase commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What I did

From my understanding, cli.StatusError means the container's command ran and exited non-zero. Hence, that's not a compose failure, but the command's own exit code. Returning a non-nil err alongside it made callers treat a normal exit as a tool error. Now it just passes the exit code through.

(not mandatory) A picture of a cute animal, if possible in relation to what you did

Signed-off-by: vmphase <vmphasee@gmail.com>
@vmphase vmphase requested a review from a team as a code owner June 24, 2026 15:48
@vmphase vmphase requested review from glours and ndeloof June 24, 2026 15:48
@vmphase vmphase force-pushed the fix/exec-nil-error branch from 2dcbf52 to 59acaa4 Compare June 24, 2026 15:49

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider this from the public API perspective, not only from the Compose CLI behavior.

This changes the implementation of api.Service.Exec(ctx, projectName, options) (int, error). API clients may rely on receiving both the structured exit code and the original error value, and may inspect or wrap that error on their side. Returning (statusCode, nil) removes that context and makes it impossible for callers to recover any details carried by the original error.

Even if the current error often only contains the exit code, preserving it keeps the API more expressive for non-CLI consumers.

@vmphase

vmphase commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

I think we should consider this from the public API perspective, not only from the Compose CLI behavior.

This changes the implementation of api.Service.Exec(ctx, projectName, options) (int, error). API clients may rely on receiving both the structured exit code and the original error value, and may inspect or wrap that error on their side. Returning (statusCode, nil) removes that context and makes it impossible for callers to recover any details carried by the original error.

Even if the current error often only contains the exit code, preserving it keeps the API more expressive for non-CLI consumers.

Fair. However, IMO, returning both a non-zero status code and a non-nil error for a successful exec (where the command exited non-zero) is ambiguous. Callers have to decide whether to treat the error/status code as authoritative. Might be worth documenting the current behavior explicitly.

@vmphase vmphase closed this Jun 30, 2026
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.

2 participants