{"record":{"id":"d311bf2d032ea9ad","repo":"hashicorp/nomad","slug":"error-formatting-w","errorCode":null,"errorMessage":"Error formatting: %w","messagePattern":"Error formatting: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/volume_status_csi.go","lineNumber":37,"sourceCode":"\tif id == \"\" {\n\t\treturn c.csiVolumesList(client, opts)\n\t}\n\n\t// get a CSI volume that matches the given prefix or a list of all matches if an\n\t// exact match is not found.\n\tvolStub, possible, err := getByPrefix[api.CSIVolumeListStub](\"volumes\", client.CSIVolumes().List,\n\t\tfunc(vol *api.CSIVolumeListStub, prefix string) bool { return vol.ID == prefix },\n\t\t&api.QueryOptions{\n\t\t\tPrefix:    id,\n\t\t\tNamespace: c.namespace,\n\t\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error listing CSI volumes: %w\", err)\n\t}\n\tif len(possible) > 0 {\n\t\tout, err := csiFormatVolumes(possible, c.json, c.template)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error formatting: %w\", err)\n\t\t}\n\t\treturn fmt.Errorf(\"Prefix matched multiple CSI volumes\\n\\n%s\", out)\n\t}\n\n\t// Try querying the volume\n\tvol, _, err := client.CSIVolumes().Info(volStub.ID, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error querying CSI volume: %w\", err)\n\t}\n\n\tstr, err := c.formatCSIBasic(vol)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error formatting CSI volume: %w\", err)\n\t}\n\tc.Ui.Output(str)\n\treturn nil\n}\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/volume_status_csi.go#L19-L55","documentation":"When the prefix supplied to `nomad volume status` matches more than one CSI volume, the command formats the candidate list and returns it (as an error) with `Error formatting: %w` if csiFormatVolumes itself fails. Note the formatting error is distinct from the intentional 'Prefix matched multiple CSI volumes' message, which is not a real failure but disambiguation output.","triggerScenarios":"`nomad volume status web` where multiple CSI volumes share the prefix `web`, and csiFormatVolumes fails (e.g. template rendering error with -t, or internal format error).","commonSituations":"Using a too-short ID prefix combined with `-t` templates referencing nonexistent fields; Go template syntax errors on the command line.","solutions":["Use a longer/volume ID prefix so exactly one volume matches, eliminating the multi-match path.","If using -t/-json, fix the template expression (test it with a simpler field like .ID).","List volumes first (`nomad volume status` with no argument) to get the exact ID."],"exampleFix":"// before\nnomad volume status web -t '{{.BadField}'\n// after\nnomad volume status 4e6c3f8a-... -t '{{.ID}} {{.Name}}'","handlingStrategy":"fallback","validationCode":"// disambiguate before asking for a single volume\npossible, _ := client.CSIVolumes().List(&api.QueryOptions{Prefix: id})\nif len(possible) > 1 {\n\tfor _, v := range possible { fmt.Println(v.ID) }\n\treturn fmt.Errorf(\"prefix %q is ambiguous; pick one ID\", id)\n}","typeGuard":null,"tryCatchPattern":"out, err := csiFormatVolumes(possible, json, tmpl)\nif err != nil {\n\treturn fmt.Errorf(\"Error formatting: %w\", err)\n}","preventionTips":["Use full volume IDs in scripts instead of short prefixes.","Test -t templates with simple fields before composing complex ones.","Avoid ambiguous prefixes in automation; fail fast on len(possible) > 1."],"tags":["nomad-cli","csi","template","prefix-match"],"backgroundTag":"ambiguous-prefix-match","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}