{"record":{"id":"d63ac274fa55cde3","repo":"docker/cli","slug":"invalid-empty-volume-spec","errorCode":null,"errorMessage":"invalid empty volume spec","messagePattern":"invalid empty volume spec","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/volumespec/volumespec.go","lineNumber":25,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n\t\"slices\"\n\t\"strings\"\n\t\"unicode\"\n\t\"unicode/utf8\"\n\n\t\"github.com/moby/moby/api/types/mount\"\n)\n\nconst endOfSpec = rune(0)\n\n// Parse parses a volume spec without any knowledge of the target platform\nfunc Parse(spec string) (VolumeConfig, error) {\n\tvolume := VolumeConfig{}\n\n\tswitch len(spec) {\n\tcase 0:\n\t\treturn volume, errors.New(\"invalid empty volume spec\")\n\tcase 1, 2:\n\t\tvolume.Target = spec\n\t\tvolume.Type = string(mount.TypeVolume)\n\t\treturn volume, nil\n\t}\n\n\tbuffer := make([]rune, 0, len(spec))\n\tfor _, char := range spec + string(endOfSpec) {\n\t\tswitch {\n\t\tcase isWindowsDrive(buffer, char):\n\t\t\tbuffer = append(buffer, char)\n\t\tcase char == ':' || char == endOfSpec:\n\t\t\tif err := populateFieldFromBuffer(char, buffer, &volume); err != nil {\n\t\t\t\tpopulateType(&volume)\n\t\t\t\treturn volume, fmt.Errorf(\"invalid spec: %s: %w\", spec, err)\n\t\t\t}\n\t\t\tbuffer = buffer[:0] // reset, but reuse capacity\n\t\tdefault:","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/internal/volumespec/volumespec.go#L7-L43","documentation":"Returned by volumespec.Parse (internal/volumespec/volumespec.go:25) when the input string has length 0. The parser requires at least some content to determine the volume type and target. This is the earliest possible validation failure in the volume-spec parsing pipeline.","triggerScenarios":"volumespec.Parse(\"\") is called — the spec string is empty. This can happen when a -v flag receives an empty value, a variable expansion produces an empty string, or Parse is called programmatically with an empty argument.","commonSituations":"Shell variable that expands to empty passed to -v (e.g., -v \"$MY_VOLUME\" where MY_VOLUME is unset), empty string in a compose file volume definition, programmatic Parse call with unvalidated input.","solutions":["Check for empty string before calling Parse: if spec == \"\" return a clear error.","Ensure shell variables used in -v flags are set and non-empty.","Validate volume specs at configuration load time before passing to the CLI."],"exampleFix":"// before: no guard before parsing\nvol, err := volumespec.Parse(spec)\n\n// after: validate non-empty first\nif spec == \"\" {\n    return VolumeConfig{}, fmt.Errorf(\"volume spec must not be empty\")\n}\nvol, err := volumespec.Parse(spec)","handlingStrategy":"validation","validationCode":"func parseVolumeSpec(spec string) (volumespec.VolumeConfig, error) {\n    if spec == \"\" {\n        return volumespec.VolumeConfig{}, fmt.Errorf(\"volume spec must not be empty\")\n    }\n    return volumespec.Parse(spec)\n}","typeGuard":null,"tryCatchPattern":"vol, err := volumespec.Parse(spec)\nif err != nil {\n    if err.Error() == \"invalid empty volume spec\" {\n        return fmt.Errorf(\"no volume path provided: specify source and/or target\")\n    }\n    return err\n}","preventionTips":["Check for empty string before calling volumespec.Parse.","Validate shell variables used in -v/--volume flags are set and non-empty.","Add input validation at configuration load time for volume specs from files."],"tags":["volume","validation","parse","mount"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}