docker/cli · error
bad format
Error message
bad format: %s
What it means
Returned by ValidateWeightDevice (the validator behind --blkio-weight-device) when the input has no ':' separator or the device-path part is empty. Expected format: '<device-path>:<weight>'.
Solutions
- Provide the full '<device-path>:<weight>' pair, e.g. '--blkio-weight-device=/dev/sda:200'.
- Keep the device on the left, weight on the right.
- Use multiple flags for multiple devices rather than comma-separating in one value.
Example fix
# before docker run --blkio-weight-device=200 ubuntu # after docker run --blkio-weight-device=/dev/sda:200 ubuntu
Defensive patterns
Strategy: validation
Validate before calling
// Require the '<device>:<weight>' shape before ValidateWeightDevice.
import "strings"
func hasWeightShape(s string) bool {
k, v, ok := strings.Cut(s, ":")
return ok && k != "" && v != ""
}
// if !hasWeightShape(val) { return fmt.Errorf("expected <device-path>:<weight>, got %q", val) } Try / catch
if _, err := opts.ValidateWeightDevice(val); err != nil {
return err // bad format: <val>
} Prevention
- Always pair a device path with a weight, separated by a colon.
- Repeat the flag per device rather than comma-separating.
- Put device on the left, weight on the right.
When it happens
Trigger: 'docker run --blkio-weight-device=200' (no device), '...=:200' (empty device key).
Common situations: User passes only a weight assuming a global default, or forgets the colon/device pair.
Related errors
- bad format for device path
- invalid weight for device
- bad format
- bad format for device path
- invalid rate for device
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/1518ccdf87dbdef0.
Report an issue: GitHub.
Appendix: source
Thrown at opts/weightdevice.go:18
package opts
import (
"fmt"
"strconv"
"strings"
"github.com/moby/moby/api/types/blkiodev"
)
// ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.
type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)
// ValidateWeightDevice validates that the specified string has a valid device-weight format.
func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) {
k, v, ok := strings.Cut(val, ":")
if !ok || k == "" {
return nil, fmt.Errorf("bad format: %s", val)
}
// TODO(thaJeztah): should we really validate this on the client?
if !strings.HasPrefix(k, "/dev/") {
return nil, fmt.Errorf("bad format for device path: %s", val)
}
weight, err := strconv.ParseUint(v, 10, 16)
if err != nil {
return nil, fmt.Errorf("invalid weight for device: %s", val)
}
if weight > 0 && (weight < 10 || weight > 1000) {
return nil, fmt.Errorf("invalid weight for device: %s", val)
}
return &blkiodev.WeightDevice{
Path: k,
Weight: uint16(weight),
}, nil
}View on GitHub (pinned to 4f84911bfe)