hashicorp/nomad · error
invalid capacity: %v
Error message
invalid capacity: %v
What it means
After HCL decoding, decodeHostVolume parses the `capacity` block/attribute with parseCapacityBytes. If that helper fails (missing value, unparsable size string, negative or non-integer bytes), the error is wrapped with `invalid capacity: %v`. The original parseCapacityBytes message is preserved after the prefix.
Source
Thrown at command/volume_create_host.go:242
}
// Need to manually parse these fields/blocks
delete(m, "capability")
delete(m, "constraint")
delete(m, "capacity")
delete(m, "capacity_max")
delete(m, "capacity_min")
delete(m, "type")
// Decode the rest
err = mapstructure.WeakDecode(m, vol)
if err != nil {
return nil, err
}
capacity, err := parseCapacityBytes(list.Filter("capacity"))
if err != nil {
return nil, fmt.Errorf("invalid capacity: %v", err)
}
vol.CapacityBytes = capacity
capacityMin, err := parseCapacityBytes(list.Filter("capacity_min"))
if err != nil {
return nil, fmt.Errorf("invalid capacity_min: %v", err)
}
vol.RequestedCapacityMinBytes = capacityMin
capacityMax, err := parseCapacityBytes(list.Filter("capacity_max"))
if err != nil {
return nil, fmt.Errorf("invalid capacity_max: %v", err)
}
vol.RequestedCapacityMaxBytes = capacityMax
if o := list.Filter("constraint"); len(o.Items) > 0 {
if err := parseConstraints(&vol.Constraints, o); err != nil {
return nil, fmt.Errorf("invalid constraint: %v", err)
}
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Use an accepted byte-size string, e.g. `capacity = "10GiB"` or `capacity = "500GB"`
- Check the exact inner error after `invalid capacity:` — it names the underlying parse failure
- Remove commas/underscores/whitespace from the number; use plain digits plus a unit suffix
- If capacity should be omitted, delete the key rather than setting it to an empty string
Example fix
// before capacity = "10 Gi" // after capacity = "10GiB"
Defensive patterns
Strategy: validation
Validate before calling
func validCapacity(s string) error {
if _, err := units.RAMInBytes(s); err != nil {
return fmt.Errorf("capacity %q is not a valid byte size: %v", s, err)
}
return nil
}
// validate each capacity field before writing/submitting the spec Try / catch
_, err := parseCapacityBytes(list.Filter("capacity"))
if err != nil {
return fmt.Errorf("fix `capacity` in the volume spec to a size like 10GiB: %v", err)
} Prevention
- Use documented unit suffixes: B, KB, MB, GB, TB, KiB, MiB, GiB, TiB
- Never include commas or spaces in size values
- Keep capacity_min <= capacity <= capacity_max
- Validate specs in CI with a dry-run parse
When it happens
Trigger: `nomad volume create` with a host volume HCL spec containing a `capacity` key whose value cannot be parsed as a byte size (e.g. `capacity = "ten GiB"`, `capacity = "-5GB"`, or an empty block).
Common situations: Typos in unit suffixes ("10Gi", "10 gibs"), using SI/binary prefixes Nomad doesn't accept, localizing numbers ("10,5 GB"), or forgetting the value entirely.
Related errors
- invalid capacity_min: %v
- invalid capacity_max: %v
- <combined HCL diagnostics from str.String()>
- invalid variables limit: %v
- %s must be integer; got (%T) %[2]v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/cfc888894d925fe9.
Report an issue: GitHub.