{"record":{"id":"bde475062c009428","repo":"docker/cli","slug":"bad-format-s","errorCode":null,"errorMessage":"bad format: %s","messagePattern":"bad format: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/throttledevice.go","lineNumber":19,"sourceCode":"package opts\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/docker/go-units\"\n\t\"github.com/moby/moby/api/types/blkiodev\"\n)\n\n// ValidatorThrottleFctType defines a validator function that returns a validated struct and/or an error.\ntype ValidatorThrottleFctType func(val string) (*blkiodev.ThrottleDevice, error)\n\n// ValidateThrottleBpsDevice validates that the specified string has a valid device-rate format.\nfunc ValidateThrottleBpsDevice(val string) (*blkiodev.ThrottleDevice, error) {\n\tk, v, ok := strings.Cut(val, \":\")\n\tif !ok || k == \"\" {\n\t\treturn nil, fmt.Errorf(\"bad format: %s\", val)\n\t}\n\t// TODO(thaJeztah): should we really validate this on the client?\n\tif !strings.HasPrefix(k, \"/dev/\") {\n\t\treturn nil, fmt.Errorf(\"bad format for device path: %s\", val)\n\t}\n\trate, err := units.RAMInBytes(v)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb\", val)\n\t}\n\tif rate < 0 {\n\t\treturn nil, fmt.Errorf(\"invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb\", val)\n\t}\n\n\treturn &blkiodev.ThrottleDevice{\n\t\tPath: k,\n\t\tRate: uint64(rate),\n\t}, nil\n}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/throttledevice.go#L1-L37","documentation":"Returned by ValidateThrottleBpsDevice (the validator behind --device-read-bps / --device-write-bps) when the input has no ':' separator or the device-path part (left of ':') is empty. The expected format is '<device-path>:<number>[<unit>]'.","triggerScenarios":"'docker run --device-read-bps=1mb' (no colon, no device), '--device-read-bps=:1mb' (empty device key), or any value where strings.Cut(val, \":\") yields ok=false.","commonSituations":"Forgetting the device path and passing only a rate, or swapping the order ('1mb:/dev/sda'). Happens when users assume the flag takes just a rate and apply it globally.","solutions":["Provide the full '<device-path>:<rate>' pair, e.g. '--device-read-bps=/dev/sda:1mb'.","Put the device path on the left of the colon and the rate on the right.","Ensure the device path is non-empty (starts with /dev/ — see the next check)."],"exampleFix":"# before\ndocker run --device-read-bps=1mb ubuntu\n# after\ndocker run --device-read-bps=/dev/sda:1mb ubuntu","handlingStrategy":"validation","validationCode":"// Reject values missing the '<device>:<rate>' shape before ValidateThrottleBpsDevice.\nimport \"strings\"\n\nfunc hasBpsShape(s string) bool {\n    k, v, ok := strings.Cut(s, \":\")\n    return ok && k != \"\" && v != \"\"\n}\n\n// if !hasBpsShape(val) { return fmt.Errorf(\"expected <device-path>:<rate>, got %q\", val) }","typeGuard":null,"tryCatchPattern":"if _, err := opts.ValidateThrottleBpsDevice(val); err != nil {\n    // err: bad format: <val>\n    return err\n}","preventionTips":["Always include both the device path and the rate, separated by a colon.","Put the device on the left, rate on the right.","Pre-flight with a 'strings.Cut(s, \":\")' shape check in your wrapper."],"tags":["docker","blkio","throttle","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}