{"record":{"id":"c906a1b9cfde2054","repo":"docker/cli","slug":"invalid-count-s-value-must-be-either-all-or","errorCode":null,"errorMessage":"invalid count (%s): value must be either \"all\" or an integer: %w","messagePattern":"invalid count \\((.+?)\\): value must be either \"all\" or an integer: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/gpus.go","lineNumber":28,"sourceCode":"\t\"github.com/moby/moby/api/types/container\"\n)\n\n// GpuOpts is a Value type for parsing mounts\ntype GpuOpts struct {\n\tvalues []container.DeviceRequest\n}\n\nfunc parseCount(s string) (int, error) {\n\tif s == \"all\" {\n\t\treturn -1, nil\n\t}\n\ti, err := strconv.Atoi(s)\n\tif err != nil {\n\t\tvar numErr *strconv.NumError\n\t\tif errors.As(err, &numErr) {\n\t\t\terr = numErr.Err\n\t\t}\n\t\treturn 0, fmt.Errorf(`invalid count (%s): value must be either \"all\" or an integer: %w`, s, err)\n\t}\n\treturn i, nil\n}\n\n// Set a new mount value\n//\n//nolint:gocyclo\nfunc (o *GpuOpts) Set(value string) error {\n\tcsvReader := csv.NewReader(strings.NewReader(value))\n\tfields, err := csvReader.Read()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treq := container.DeviceRequest{}\n\n\tseen := map[string]struct{}{}\n\t// Set writable as the default","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/gpus.go#L10-L46","documentation":"parseCount accepts exactly the literal string \"all\" (mapped to -1) or a base-10 integer. Anything else — a float, a spelled-out number, \"all2\", or non-numeric text — fails strconv.Atoi and is wrapped here with the underlying NumError. The GPU count has a very narrow grammar.","triggerScenarios":"Passing --gpus a count that is neither \"all\" nor an integer, e.g. --gpus 1.5, --gpus two, or --gpus count=1.5.","commonSituations":"Typo in the count; passing a fractional GPU count; misunderstanding that only \"all\" or an int are allowed.","solutions":["Use an integer: --gpus 2, or the key form --gpus count=2.","Use the literal --gpus all to request every GPU.","Strip stray characters/whitespace from the value before parsing.","Validate the field with parseCount (or strconv.Atoi + \"all\" check) before invoking Set."],"exampleFix":"# before\ndocker run --gpus 1.5 myimg\n\n# after\ndocker run --gpus 2 myimg   # or --gpus all","handlingStrategy":"validation","validationCode":"// Validate a GPU count string the same way parseCount does.\nfunc validGpuCount(s string) error {\n    if s == \"all\" {\n        return nil\n    }\n    if _, err := strconv.Atoi(s); err != nil {\n        return fmt.Errorf(`count must be \"all\" or an integer, got %q`, s)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use an integer or the literal \"all\" for GPU counts.","Trim whitespace before parsing programmatically supplied values.","Validate count fields before calling GpuOpts.Set."],"tags":["docker","gpu","parsing","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}