Skip to content

fix(compose): reject unknown subcommands under bridge/transformations - #14143

Open
glours wants to merge 1 commit into
docker:mainfrom
glours:fix/bridge-unknown-subcommand-exit-code
Open

fix(compose): reject unknown subcommands under bridge/transformations#14143
glours wants to merge 1 commit into
docker:mainfrom
glours:fix/bridge-unknown-subcommand-exit-code

Conversation

@glours

@glours glours commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What I did
bridgeCommand and transformersCommand had no RunE, so an unknown subcommand (e.g. "bridge zzz") fell through cobra's default non-Runnable path: help printed, exit 0. Scripts couldn't distinguish a typo from success. Mirrors the same fix already shipped on the compose root command.

Related issue
https://docker.atlassian.net/browse/DDB-666

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

@glours
glours requested review from a team as code owners August 27, 2026 13:00
@glours
glours requested a review from ndeloof August 27, 2026 13:00
@glours glours self-assigned this Aug 27, 2026

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

The PR correctly wires rejectUnknownSubcommand as RunE on the bridgeCommand and transformersCommand parent commands so that unknown subcommands exit 1 instead of 0. The core logic is sound: cobra dispatches unknown tokens to the parent's RunE, known subcommands are dispatched directly so the new guard is never incorrectly invoked, and the tests cover all the key scenarios (unknown subcommand, no subcommand, nested transformations).

One low-severity finding below: a discarded cmd.Help() error in the non-zero-args path.

Comment thread cmd/compose/bridge.go
if len(args) == 0 {
return cmd.Help()
}
_ = cmd.Help()

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.

[low] Error from cmd.Help() silently discarded before returning StatusError

When args is non-empty, rejectUnknownSubcommand calls _ = cmd.Help() and discards the error before returning the cli.StatusError. If the cobra output writer returns an I/O error (e.g. a broken pipe), the help text won't render and the error will be silently swallowed — the caller only sees the StatusError, with no indication that help rendering failed and no help context displayed.

The conventional Go pattern is to propagate the error:

Suggested change
_ = cmd.Help()
if err := cmd.Help(); err != nil {
return err
}
Confidence Score
🟢 strong 100/100

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

bridgeCommand and transformersCommand had no RunE, so an unknown
subcommand (e.g. "bridge zzz") fell through cobra's default
non-Runnable path: help printed, exit 0. Scripts couldn't distinguish
a typo from success. Mirrors the same fix already shipped on the
compose root command.

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
@glours
glours force-pushed the fix/bridge-unknown-subcommand-exit-code branch from d382891 to dcea158 Compare August 27, 2026 13:14
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