{"record":{"id":"079aa27b100a3dbd","repo":"docker/cli","slug":"bad-format-for-device-path-s-079aa2","errorCode":null,"errorMessage":"bad format for device path: %s","messagePattern":"bad format for device path: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/weightdevice.go","lineNumber":22,"sourceCode":"\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/moby/moby/api/types/blkiodev\"\n)\n\n// ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.\ntype ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)\n\n// ValidateWeightDevice validates that the specified string has a valid device-weight format.\nfunc ValidateWeightDevice(val string) (*blkiodev.WeightDevice, 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\tweight, err := strconv.ParseUint(v, 10, 16)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid weight for device: %s\", val)\n\t}\n\tif weight > 0 && (weight < 10 || weight > 1000) {\n\t\treturn nil, fmt.Errorf(\"invalid weight for device: %s\", val)\n\t}\n\n\treturn &blkiodev.WeightDevice{\n\t\tPath:   k,\n\t\tWeight: uint16(weight),\n\t}, nil\n}\n\n// WeightdeviceOpt defines a map of WeightDevices\ntype WeightdeviceOpt struct {\n\tvalues    []*blkiodev.WeightDevice","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/weightdevice.go#L4-L40","documentation":"Returned by ValidateWeightDevice when the device-path portion of a --blkio-weight-device value does not start with '/dev/'. Client-side prefix enforcement shared with the throttle validators.","triggerScenarios":"'docker run --blkio-weight-device=sda:200' or '...=dev/sda:200' — key lacks the '/dev/' prefix.","commonSituations":"Passing a bare device name or sysfs path instead of the /dev node.","solutions":["Use the full /dev path: '--blkio-weight-device=/dev/sda:200'.","Verify the node with 'lsblk' / 'ls /dev' before passing it.","Keep the /dev/ prefix for nvme, dm-, md, etc."],"exampleFix":"# before\ndocker run --blkio-weight-device=sda:200 ubuntu\n# after\ndocker run --blkio-weight-device=/dev/sda:200 ubuntu","handlingStrategy":"validation","validationCode":"// Enforce the /dev/ prefix the weight validator requires.\nimport \"strings\"\n\nfunc weightDevOk(s string) bool {\n    k, _, ok := strings.Cut(s, \":\")\n    return ok && strings.HasPrefix(k, \"/dev/\")\n}\n\n// if !weightDevOk(val) { return fmt.Errorf(\"device path must start with /dev/: %q\", val) }","typeGuard":null,"tryCatchPattern":"if _, err := opts.ValidateWeightDevice(val); err != nil {\n    return err // bad format for device path: <val>\n}","preventionTips":["Always use the full /dev node path.","Verify devices with lsblk before scripting.","Never pass a bare disk name to a blkio flag."],"tags":["docker","blkio","weight","device-path","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}