Skip to content

api: reject incompatible Up options with a typed error - #14306

Open
ndeloof wants to merge 1 commit into
docker:mainfrom
ndeloof:up-options-validation
Open

ndeloof wants to merge 1 commit into
docker:mainfrom
ndeloof:up-options-validation

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

Up now refuses, with a dedicated api.IncompatibleOptionsError, the option combinations the CLI already refuses, instead of leaving a library caller with silently ignored options.

Context

The CLI validates its flags (validateFlags): --wait cannot be combined with --attach/--attach-dependencies, and --detach cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --exit-code-from or --watch. None of this exists at the API level: a program using the library can set Start.Wait together with Start.Attach, get an interactive session, and never learn that the wait was dropped; likewise OnExit, ExitCodeFrom and Watch are session-only options that are silently ignored when Attach is nil. The first case is the Attach + Wait gap noticed while working on #14081.

What the PR brings

  • UpOptions.Validate(), a pure function, called first thing by Up (before any call to the engine or any progress event). It returns an *api.IncompatibleOptionsError carrying the conflicting fields and the reason; errors.Is(err, api.ErrIncompatibleOptions) and errors.As both work. Integrators can also call it themselves to fail early.
  • Rules, each mirroring a CLI one ("detached" is Start.Attach == nil):
    • Wait with Attach set: CLI --wait implies detached and is incompatible with --attach/--attach-dependencies.
    • detached with OnExit other than CascadeIgnore: CLI --detach vs --abort-on-container-exit/--abort-on-container-failure.
    • detached with ExitCodeFrom: CLI --detach vs --exit-code-from (which implies --abort-on-container-exit).
    • detached with Watch: CLI --detach (and --wait) vs --watch.
  • The CLI is untouched: same flags, same messages, it still validates first. Everything the CLI can send to Up already passes the new validation, and the existing up/cascade/wait e2e tests pass.
  • Deliberately not ported, because the API does not have the same meaning as the flags: --no-recreate vs --renew-anon-volumes (the zero value of Create.Inherit is false, so existing callers leaving it unset would be rejected), --no-recreate vs --always-recreate-deps and --force-recreate (Recreate and RecreateDependencies are separate strategies at the API level), --build vs --no-build (not representable), --no-build vs --watch (a nil Create.Build still allows sync-only watch, and rebuild triggers already fail on their own), and a negative --wait-timeout (not a combination of options). AttachTo with a nil Attach is also left alone, since Start uses AttachTo to rebuild a project from labels.

This does change behavior for integrators: a program that passed one of the above combinations used to get an undefined (usually silently degraded) behavior and now gets an error from Up. That is the point, but it is worth a release note.

Why this is the right next brick

It is independent of the switchover work: the logic lives in its own file and Up only gains a single guard call, so it can land before or after #14305 without touching the engine path. Related to #14081.

🤖 Generated with Claude Code

@ndeloof
ndeloof requested review from docker-agent and a balanced review from Copilot October 8, 2026 11:48

Copilot AI 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.

🟡 Changes recommended

The public error message reverses the detached-option relationship, and the validation documentation overstates its scope.

2 open findings
What changed in this PR

Adds API-level validation for incompatible Up options before side effects occur.

Changes:

  • Introduces a typed incompatible-options error and sentinel.
  • Validates detached, attached, wait, watch, and exit-policy combinations.
  • Adds API and service-level unit tests.
File Description
pkg/​api/​errors.go Defines the error sentinel and helper.
pkg/​api/​up_options.go Implements typed errors and validation.
pkg/​api/​up_options_test.go Tests validation combinations and error behavior.
pkg/​compose/​up.go Validates options before executing Up.
pkg/​compose/​up_options_test.go Verifies rejection occurs before side effects.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread pkg/api/up_options.go Outdated
Comment thread pkg/api/up_options.go Outdated

@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

@ndeloof
ndeloof force-pushed the up-options-validation branch from 7837eea to 90ae075 Compare October 8, 2026 11:53
@ndeloof
ndeloof requested review from docker-agent and a balanced review from Copilot October 8, 2026 11:53

Copilot AI 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.

🟢 Approval recommended

The validation behavior is consistent with the documented API semantics and is thoroughly covered by focused tests.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@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: 🟡 NEEDS ATTENTION

Comment thread pkg/api/up_options.go Outdated
Comment thread pkg/api/up_options.go Outdated
The CLI refuses combinations such as --wait with --attach, or --detach with
--abort-on-container-exit, --exit-code-from or --watch. The library did not:
an integrator setting Start.Wait together with Start.Attach got an
interactive session in which the wait was silently dropped, and the
session-only options were silently ignored when Attach is nil.

Add UpOptions.Validate, called first thing by Up, which returns an
*IncompatibleOptionsError matching api.ErrIncompatibleOptions. The CLI is
unchanged.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested a review from docker-agent October 8, 2026 12:55
@ndeloof
ndeloof force-pushed the up-options-validation branch from 90ae075 to 04fe4bc Compare October 8, 2026 12:55
@ndeloof
ndeloof requested a balanced review from Copilot October 8, 2026 12:55

Copilot AI 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.

🟢 Approval recommended

The validation behavior is well-scoped, documented, and comprehensively tested.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@ndeloof
ndeloof marked this pull request as ready for review October 8, 2026 14:50
@ndeloof
ndeloof requested review from a team as code owners October 8, 2026 14:50
@ndeloof
ndeloof requested a review from glours October 8, 2026 14:50

@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

This branch has not been deployed

No deployments
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.

3 participants