{"record":{"id":"db5f231216f1fda3","repo":"docker/cli","slug":"unexpected-key-s-in-s","errorCode":null,"errorMessage":"unexpected key '%s' in '%s'","messagePattern":"unexpected key '(.+?)' in '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/gpus.go","lineNumber":83,"sourceCode":"\t\t\treq.Driver = val\n\t\tcase \"count\":\n\t\t\treq.Count, err = parseCount(val)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\tcase \"device\":\n\t\t\treq.DeviceIDs = strings.Split(val, \",\")\n\t\tcase \"capabilities\":\n\t\t\treq.Capabilities = [][]string{append(strings.Split(val, \",\"), \"gpu\")}\n\t\tcase \"options\":\n\t\t\tr := csv.NewReader(strings.NewReader(val))\n\t\t\toptFields, err := r.Read()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to read gpu options: %w\", err)\n\t\t\t}\n\t\t\treq.Options = ConvertKVStringsToMap(optFields)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unexpected key '%s' in '%s'\", key, field)\n\t\t}\n\t}\n\n\tif _, ok := seen[\"count\"]; !ok && req.DeviceIDs == nil {\n\t\treq.Count = 1\n\t}\n\tif req.Options == nil {\n\t\treq.Options = make(map[string]string)\n\t}\n\tif req.Capabilities == nil {\n\t\treq.Capabilities = [][]string{{\"gpu\"}}\n\t}\n\n\to.values = append(o.values, req)\n\treturn nil\n}\n\n// Type returns the type of this option","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/gpus.go#L65-L101","documentation":"GpuOpts.Set only recognizes the keys driver, count, device, capabilities, options (plus a bare integer shorthand for count). Any other key=value or unknown token reaches the default branch and is rejected with the offending key and field echoed back.","triggerScenarios":"--gpus with an unknown key, e.g. --gpus 'foo=bar', --gpus 'gpus=2', or a misspelled valid key like --gpus 'capabilties=compute'.","commonSituations":"Typo in a key; assuming a key exists that the GPU request grammar does not define; copy-paste from a different tool's syntax.","solutions":["Use only valid keys: driver, count, device, capabilities, options.","Check spelling against the documented grammar.","Use a bare integer for count shorthand (--gpus 2).","If constructing the value in code, validate keys against the whitelist before calling Set."],"exampleFix":"# before\ndocker run --gpus 'gpus=2' myimg\n\n# after\ndocker run --gpus 'count=2,driver=nvidia' myimg","handlingStrategy":"validation","validationCode":"var gpuKeys = map[string]bool{\"driver\": true, \"count\": true, \"device\": true, \"capabilities\": true, \"options\": true}\n\nfunc validGpuFields(fields []string) error {\n    for _, f := range fields {\n        key, _, ok := strings.Cut(f, \"=\")\n        if !ok {\n            key = \"count\" // bare integer shorthand\n        }\n        if !gpuKeys[key] {\n            return fmt.Errorf(\"unexpected gpu key %q\", key)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict keys to driver, count, device, capabilities, options.","Validate keys at the input boundary when building --gpus values programmatically.","Double-check spelling of capability/capabilities."],"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"}