{"record":{"id":"cfc888894d925fe9","repo":"hashicorp/nomad","slug":"invalid-capacity-v","errorCode":null,"errorMessage":"invalid capacity: %v","messagePattern":"invalid capacity: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/volume_create_host.go","lineNumber":242,"sourceCode":"\t}\n\n\t// Need to manually parse these fields/blocks\n\tdelete(m, \"capability\")\n\tdelete(m, \"constraint\")\n\tdelete(m, \"capacity\")\n\tdelete(m, \"capacity_max\")\n\tdelete(m, \"capacity_min\")\n\tdelete(m, \"type\")\n\n\t// Decode the rest\n\terr = mapstructure.WeakDecode(m, vol)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcapacity, err := parseCapacityBytes(list.Filter(\"capacity\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid capacity: %v\", err)\n\t}\n\tvol.CapacityBytes = capacity\n\tcapacityMin, err := parseCapacityBytes(list.Filter(\"capacity_min\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid capacity_min: %v\", err)\n\t}\n\tvol.RequestedCapacityMinBytes = capacityMin\n\tcapacityMax, err := parseCapacityBytes(list.Filter(\"capacity_max\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid capacity_max: %v\", err)\n\t}\n\tvol.RequestedCapacityMaxBytes = capacityMax\n\n\tif o := list.Filter(\"constraint\"); len(o.Items) > 0 {\n\t\tif err := parseConstraints(&vol.Constraints, o); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid constraint: %v\", err)\n\t\t}\n\t}","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/volume_create_host.go#L224-L260","documentation":"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.","triggerScenarios":"`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).","commonSituations":"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.","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"],"exampleFix":"// before\ncapacity = \"10 Gi\"\n\n// after\ncapacity = \"10GiB\"","handlingStrategy":"validation","validationCode":"func validCapacity(s string) error {\n\tif _, err := units.RAMInBytes(s); err != nil {\n\t\treturn fmt.Errorf(\"capacity %q is not a valid byte size: %v\", s, err)\n\t}\n\treturn nil\n}\n// validate each capacity field before writing/submitting the spec","typeGuard":null,"tryCatchPattern":"_, err := parseCapacityBytes(list.Filter(\"capacity\"))\nif err != nil {\n\treturn fmt.Errorf(\"fix `capacity` in the volume spec to a size like 10GiB: %v\", err)\n}","preventionTips":["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"],"tags":["hcl","nomad","validation","bytes"],"backgroundTag":"invalid-capacity-string","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}