{"record":{"id":"2a0a1699de5e623b","repo":"docker/cli","slug":"failed-to-read-gpu-options-w","errorCode":null,"errorMessage":"failed to read gpu options: %w","messagePattern":"failed to read gpu options: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/gpus.go","lineNumber":79,"sourceCode":"\t\t}\n\n\t\tswitch key {\n\t\tcase \"driver\":\n\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)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/gpus.go#L61-L97","documentation":"The options= field is itself parsed as CSV via csv.Reader. If that read fails — typically an unterminated quote or otherwise malformed CSV inside the options value — the csv error is wrapped here. The surrounding GPU value parsed fine; only the nested options CSV is broken.","triggerScenarios":"--gpus 'options=...' where the options value is malformed CSV, e.g. an unmatched double-quote, a stray quote, or illegal quoting of embedded commas.","commonSituations":"Forgetting to quote key=value pairs that contain commas; unbalanced quotes when passing options; shell-quoting mistakes.","solutions":["Quote each CSV field properly: options=\"k=v\",\"k2=v2\".","Avoid commas inside option values, or quote them per RFC 4180.","Pre-parse the options substring with encoding/csv in a test to catch quoting errors early.","Simplify by omitting options if unused."],"exampleFix":"# before\ndocker run --gpus 'options=a=1,b=2' myimg   # ambiguous\n\n# after (proper CSV quoting)\ndocker run --gpus 'options=\"a=1\",\"b=2\"' myimg","handlingStrategy":"validation","validationCode":"// Pre-parse the options= value as CSV to catch quoting errors early.\nfunc validOptionsCSV(val string) error {\n    r := csv.NewReader(strings.NewReader(val))\n    _, err := r.Read()\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote each CSV field in options values (\"k=v\",\"k2=v2\").","Avoid embedded commas or quote them per RFC 4180.","Test programmatic options strings with encoding/csv before passing them in."],"tags":["docker","gpu","parsing","csv"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}