{"record":{"id":"ed273418a2dd8a26","repo":"docker/cli","slug":"value-is-empty","errorCode":null,"errorMessage":"value is empty","messagePattern":"value is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/mount.go","lineNumber":27,"sourceCode":"\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/docker/go-units\"\n\tmounttypes \"github.com/moby/moby/api/types/mount\"\n)\n\n// MountOpt is a Value type for parsing mounts\ntype MountOpt struct {\n\tvalues []mounttypes.Mount\n}\n\n// Set a new mount value\n//\n//nolint:gocyclo\nfunc (m *MountOpt) Set(value string) error {\n\tvalue = strings.TrimSpace(value)\n\tif value == \"\" {\n\t\treturn errors.New(\"value is empty\")\n\t}\n\n\tcsvReader := csv.NewReader(strings.NewReader(value))\n\tfields, err := csvReader.Read()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tmount := mounttypes.Mount{\n\t\tType: mounttypes.TypeVolume, // default to volume mounts\n\t}\n\n\tfor _, field := range fields {\n\t\tkey, val, hasValue := strings.Cut(field, \"=\")\n\t\tif k := strings.TrimSpace(key); k != key {\n\t\t\treturn fmt.Errorf(\"invalid option '%s' in '%s': option should not have whitespace\", k, field)\n\t\t}\n\t\tif hasValue {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/mount.go#L9-L45","documentation":"Returned by MountOpt.Set (opts/mount.go:27) when the value passed to a --mount flag, after strings.TrimSpace, is an empty string. This is the first validation check in the mount-option parser; an empty mount string cannot be parsed into any mount configuration.","triggerScenarios":"MountOpt.Set(\"\") or MountOpt.Set(\"   \") is called — the --mount flag receives an empty or whitespace-only value.","commonSituations":"Shell variable expansion to empty string in a --mount flag (e.g., --mount \"$MOUNT_OPTS\" where MOUNT_OPTS is unset), empty mount entry in a script or config, or a quoting error that produces an empty argument.","solutions":["Ensure the --mount flag receives a non-empty value such as 'type=volume,source=myvol,target=/data'.","Check that shell variables used in --mount are set and non-empty before use.","Skip empty mount strings programmatically rather than passing them to Set."],"exampleFix":"// before: empty mount value\n// docker run --mount \"\" nginx\n\n// after: valid mount spec\n// docker run --mount type=volume,source=myvol,target=/data nginx","handlingStrategy":"validation","validationCode":"func validateMountValue(value string) error {\n    if strings.TrimSpace(value) == \"\" {\n        return fmt.Errorf(\"mount spec must not be empty\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := mountOpt.Set(value); err != nil {\n    if err.Error() == \"value is empty\" {\n        return fmt.Errorf(\"--mount requires a non-empty value, e.g., type=volume,source=vol,target=/data\")\n    }\n    return err\n}","preventionTips":["Skip empty mount strings rather than passing them to MountOpt.Set.","Ensure shell variables in --mount flags are set and non-empty.","Validate mount specs from config files at load time."],"tags":["mount","validation","cli-flag"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}