Repository navigation
Conversation
…nations Logs, Events, Publish and Down each accept options that cannot work, and fail late or not at all: - LogOptions.Index selects a replica of one service. With no service the lookup indexes an empty slice and panics, with several the others are silently ignored. The CLI refuses it, the library did not. - EventsOptions.Consumer is called for every event, and a nil one panics when the first arrives. - PublishOptions.OCIVersion is only checked once the layers are pushed. - DownOptions.Images was validated inline in down(), with a message nothing could match. Give each a Validate, and call it first from the operation. Invalid values match the new ErrInvalidOption (InvalidOptionError, which also covers a required option left unset through its Reason), and the Logs combination matches the existing ErrIncompatibleOptions. The message for an unknown image prune mode changes accordingly; nothing else that worked is rejected. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The PR cleanly introduces Validate() methods for LogOptions, EventsOptions, PublishOptions, and DownOptions, wired in before any side effects in the corresponding operations. The InvalidOptionError type correctly implements the errors.Is/errors.As chain via Unwrap(). No correctness bugs were found in the added code.
Lower-confidence findings (not posted inline)
- [low] pkg/api/validate.go:98 — DownOptions.Validate() omits
ImagePruneNone("") from the allowed-values list in the error message (confidence: unverified/low)- The error is only returned for truly invalid values (those that don't pass
Valid()), soImagePruneNoneis never erroneously rejected — but the error message won't tell callers that""is an accepted no-op value. Consider adding it to theAllowedslice or using a human-readable label like"none".
- The error is only returned for truly invalid values (those that don't pass
- [low] pkg/api/validate.go:50 —
InvalidOptionError.Error()produces a malformed message ("x" is not one of) whenAllowedis nil/empty andReasonis unset (confidence: unverified/low)- No current call site hits this path, but the struct is exported and third-party callers could construct it this way. A guard on
len(e.Allowed) == 0with a fallback format would make the type more robust.
- No current call site hits this path, but the struct is exported and third-party callers could construct it this way. A guard on
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The PR is well-structured and the core logic is correct. ErrInvalidOption and InvalidOptionError are properly defined (with Unwrap() ensuring errors.Is works), the Validate() methods guard the right conditions, and the early-return wiring in Logs, Events, Publish, and Down is correct. No high- or medium-severity issues were found.
Lower-confidence findings (not posted inline)
- [low]
pkg/api/validate.go:95 —DownOptions.Validate()allowed-list omits the valid empty-string valueImagePruneNonefrom the error message (confidence: unverified, low)- The
Allowedfield in the returnedInvalidOptionErrorlists only["local", "all"]; the valid zero-value""(ImagePruneNone) is not mentioned. The validation logic itself is correct —Valid()accepts the zero value — but a caller who receives the error has no way to discover from the message that""is also accepted.
- The
- [low]
pkg/api/validate.go:60 —LogOptions.Validate()error message conflates "no service" and "multiple services" into one message (confidence: unverified, low)- Both
len(o.Services) == 0andlen(o.Services) > 1are caught by the singlelen(o.Services) != 1guard, producing the message "Index selects a replica of one service, but N services are selected" for both. For N=0 this reads oddly since the problem is a missing service rather than conflicting selections.
- Both
- [low]
pkg/compose/validate_options_test.go:33 —TestOperationsRejectInvalidOptionsdoes not coverDownvalidation (confidence: unverified, low)- The test exercises
Logs,Events, andPublishbut omitsDown.Downhas its own test indown_test.go, but if the earlyValidate()call were removed fromdown.go, this integration test would not catch the regression.
- The test exercises
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟡 NEEDS ATTENTION
DownOptions.Validate omitted the empty ImagePruneNone value from the allowed list, so the error did not tell callers that "" is accepted. Quote the allowed values so an empty one stays readable, fall back to a generic message when no closed set is given, and word the Logs Index error properly when no service is selected. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
docker-agent
left a comment
There was a problem hiding this comment.
This review covers only the commits pushed since 0dfeacad47e8.
Assessment: 🟢 APPROVE
The incremental changes are correct and clean. The previously flagged issue — DownOptions.Validate() omitting ImagePruneNone from the Allowed list — has been properly fixed in this batch. All new code introduced by these commits is well-reasoned:
- The
len(e.Allowed) == 0guard inInvalidOptionError.Error()avoids a confusing empty-list message and returns a sensible fallback. - Wrapping each allowed value with
strconv.Quote()before joining them makes the empty string ("") clearly readable in error messages, consistent with the project's convention. servicesSelected(n)correctly handles both edge cases (n == 0→ "no service is selected";n > 1→ "%d services are selected");n == 1is never passed because the guardlen(o.Services) != 1gates the call.- Test expectations are updated to match the new quoted format and the new
ImagePruneNoneentry exactly. - The new
strconvimport is inserted in correct alphabetical order, compliant withgcirules.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
What this PR does, in one sentence
Gives the options of
Logs,Events,PublishandDownaValidatemethod, called first by each operation, so that values and combinations that cannot work fail early with a typed error.Context
Some options of
pkg/apiaccept values that cannot work, and fail late or not at all: aLogOptions.Indexwith no service indexes an empty slice and panics, with several services it silently looks in the first one only; a nilEventsOptions.Consumerpanics when the first event arrives; an unknownPublishOptions.OCIVersionis only noticed once the layers have been pushed; and an unknown image prune mode inDownis reported with a message nothing can match.CreateOptionsandUpOptionsalready validate up front.What the PR brings
ValidateforLogOptions,EventsOptions,PublishOptionsandDownOptions, called first byLogs,Events,PublishandDown.ErrInvalidOptionsentinel, withInvalidOptionErrorcarrying the option, the value and the accepted values (or a reason when a required option is left unset), and anIsErrInvalidOptionhelper. TheLogscombination matches the existingErrIncompatibleOptions.The CLI already refuses these cases, so it is unaffected. Two visible effects for programs using the library:
Logswith anIndexand several services now fails instead of silently using the first one, and the message for an unknown image prune mode inDownbecomes the typed error. No exported symbol is removed or changes type.This is the part of #14419 that does not depend on the rest of that PR, extracted so it can be reviewed on its own.
🤖 Generated with Claude Code