{"record":{"id":"5d2c8929989e9f16","repo":"docker/cli","slug":"invalid-generic-resource-specification-w","errorCode":null,"errorMessage":"invalid generic resource specification: %w","messagePattern":"invalid generic resource specification: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/service/generic_resource_opts.go","lineNumber":37,"sourceCode":"func ValidateSingleGenericResource(val string) (string, error) {\n\tif strings.Count(val, \"=\") < 1 {\n\t\treturn \"\", fmt.Errorf(\"invalid generic-resource format `%s` expected `name=value`\", val)\n\t}\n\n\treturn val, nil\n}\n\n// ParseGenericResources parses an array of Generic resourceResources\n// Requesting Named Generic Resources for a service is not supported this\n// is filtered here.\nfunc ParseGenericResources(value []string) ([]swarm.GenericResource, error) {\n\tif len(value) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tswarmResources, err := genericresource.Parse(value)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid generic resource specification: %w\", err)\n\t}\n\n\tfor _, res := range swarmResources {\n\t\tif res.NamedResourceSpec != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid generic-resource request `%s=%s`, Named Generic Resources is not supported for service create or update\",\n\t\t\t\tres.NamedResourceSpec.Kind, res.NamedResourceSpec.Value,\n\t\t\t)\n\t\t}\n\t}\n\n\treturn swarmResources, nil\n}\n\nfunc buildGenericResourceMap(genericRes []swarm.GenericResource) (map[string]swarm.GenericResource, error) {\n\tm := make(map[string]swarm.GenericResource)\n\n\tfor _, res := range genericRes {\n\t\tif res.DiscreteResourceSpec == nil {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/service/generic_resource_opts.go#L19-L55","documentation":"Returned by ParseGenericResources (generic_resource_opts.go:37) wrapping the error from genericresource.Parse. This fires when the input passes the superficial `=`-presence check but fails deeper parsing — typically because a discrete (numeric) resource value is not a valid integer, or the kind/value structure is malformed.","triggerScenarios":"Passing `--generic-resource \"GPU=abc\"` where the value is non-numeric for a discrete resource, or otherwise structurally invalid input that genericresource.Parse rejects.","commonSituations":"Requesting a count of GPUs/FPGAs with a non-integer value, extra whitespace breaking the parse, or mixing named and discrete syntax incorrectly.","solutions":["Use an integer value for discrete resources, e.g. `GPU=2`.","Inspect the wrapped error (%w) for the precise parse reason.","Trim whitespace and ensure exactly one `=` per entry."],"exampleFix":"// before\ndocker service create --generic-resource \"GPU=two\" --name svc img\n// after\ndocker service create --generic-resource \"GPU=2\" --name svc img","handlingStrategy":"validation","validationCode":"// Pre-parse generic resources the same way the CLI does.\nfunc validateGenericResources(entries []string) error {\n    if _, err := genericresource.Parse(entries); err != nil {\n        return fmt.Errorf(\"invalid generic resource specification: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use integer values for discrete resources.","Trim whitespace around name and value.","Surface the wrapped parse error to pinpoint the bad token."],"tags":["service","generic-resource","swarm","validation","docker-cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}