{"record":{"id":"0241f3137c050ee6","repo":"docker/cli","slug":"invalid-weight-for-device-s","errorCode":null,"errorMessage":"invalid weight for device: %s","messagePattern":"invalid weight for device: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/weightdevice.go","lineNumber":26,"sourceCode":"\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\n\tvalidator ValidatorWeightFctType\n}\n\n// NewWeightdeviceOpt creates a new WeightdeviceOpt","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/weightdevice.go#L8-L44","documentation":"Returned by ValidateWeightDevice when strconv.ParseUint(v, 10, 16) fails on the weight part of --blkio-weight-device. The weight must be a base-10 integer that fits uint16 (0..65535); non-numeric, negative, decimal, or >65535 values fail here. (Range is further constrained to 10..1000, or 0 to unset — see 671.)","triggerScenarios":"'docker run --blkio-weight-device=/dev/sda:abc', '...=/dev/sda:-5', '...=/dev/sda:1.5', or '...=/dev/sda:70000' (overflows uint16).","commonSituations":"Passing a non-numeric weight, a fractional value, a value from a variable that resolved to empty/garbage, or a weight above 65535.","solutions":["Use an integer in 10..1000 (or 0 to unset): '--blkio-weight-device=/dev/sda:200'.","Strip any unit suffix or decimal point — weights are unitless integers.","Cap the value at 1000 for a valid range (values 1001..65535 parse but fail the range check at 671)."],"exampleFix":"# before\ndocker run --blkio-weight-device=/dev/sda:1.5 ubuntu\n# after\ndocker run --blkio-weight-device=/dev/sda:200 ubuntu","handlingStrategy":"validation","validationCode":"// Weight must parse as a base-10 uint16 — check before the validator.\nimport (\"strconv\"; \"strings\")\n\nfunc weightParses(s string) bool {\n    _, v, ok := strings.Cut(s, \":\")\n    if !ok { return false }\n    _, err := strconv.ParseUint(v, 10, 16)\n    return err == nil\n}\n\n// if !weightParses(val) { return fmt.Errorf(\"weight must be an integer 0..65535, got %q\", val) }","typeGuard":null,"tryCatchPattern":"if _, err := opts.ValidateWeightDevice(val); err != nil {\n    return err // invalid weight for device: <val>\n}","preventionTips":["Weights are unitless integers — no suffixes or decimals.","Keep within uint16 (0..65535) to pass parsing; within 10..1000 (or 0) to pass range.","Sanitize templated/env values to digits only."],"tags":["docker","blkio","weight","validation","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}