{"record":{"id":"f19de084999efa85","repo":"hashicorp/nomad","slug":"either-requiredbytes-or-limitbytes-must-be-set","errorCode":null,"errorMessage":"either RequiredBytes or LimitBytes must be set","messagePattern":"either RequiredBytes or LimitBytes must be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/csi/plugin.go","lineNumber":1028,"sourceCode":"\t\tvc.AccessType = &csipbv1.VolumeCapability_Mount{Mount: opts}\n\t} else {\n\t\tvc.AccessType = &csipbv1.VolumeCapability_Block{Block: &csipbv1.VolumeCapability_BlockVolume{}}\n\t}\n\n\treturn vc\n}\n\ntype CapacityRange struct {\n\tRequiredBytes int64\n\tLimitBytes    int64\n}\n\nfunc (c *CapacityRange) Validate() error {\n\tif c == nil {\n\t\treturn nil\n\t}\n\tif c.RequiredBytes == 0 && c.LimitBytes == 0 {\n\t\treturn errors.New(\"either RequiredBytes or LimitBytes must be set\")\n\t}\n\tif c.LimitBytes > 0 && c.LimitBytes < c.RequiredBytes {\n\t\treturn errors.New(\"LimitBytes cannot be less than RequiredBytes\")\n\t}\n\treturn nil\n}\n\nfunc (c *CapacityRange) ToCSIRepresentation() *csipbv1.CapacityRange {\n\tif c == nil {\n\t\treturn nil\n\t}\n\treturn &csipbv1.CapacityRange{\n\t\tRequiredBytes: c.RequiredBytes,\n\t\tLimitBytes:    c.LimitBytes,\n\t}\n}\n\ntype NodeExpandVolumeRequest struct {","sourceCodeStart":1010,"sourceCodeEnd":1046,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/plugins/csi/plugin.go#L1010-L1046","documentation":"CapacityRange.Validate in plugins/csi/plugin.go:1028 enforces the CSI spec's requirement that a capacity range must constrain the volume size on at least one bound. If both RequiredBytes and LimitBytes are zero, the range conveys no capacity information, so the request is rejected before reaching the CSI plugin.","triggerScenarios":"Submitting a volume-create or volume-expand (NodeExpandVolumeRequest) request whose capacity_range stanza has neither required_bytes nor limit_bytes set; an empty or omitted capacity_range struct passed non-nil with zero values.","commonSituations":"Nomad volume spec (HCL/JSON) missing required_bytes under capacity_range; API clients constructing CSI volume requests programmatically and forgetting to set bytes; default-constructed Go structs passed to Validate.","solutions":["Set required_bytes (minimum size) and/or limit_bytes (maximum size) in the capacity_range block","If no capacity constraint is intended, pass a nil CapacityRange rather than a zero-valued one","Validate the volume spec with nomad volume validate before submission"],"exampleFix":"// before\ncapacity_range {}\n// after\ncapacity_range {\n  required_bytes = 1073741824\n  limit_bytes    = 2147483648\n}","handlingStrategy":"validation","validationCode":"if cr != nil && cr.RequiredBytes == 0 && cr.LimitBytes == 0 { return errors.New(\"capacity_range must set required_bytes or limit_bytes\") }","typeGuard":"func hasCapacity(c *csi.CapacityRange) bool { return c == nil || c.RequiredBytes != 0 || c.LimitBytes != 0 }","tryCatchPattern":null,"preventionTips":["Always set required_bytes in volume specs","Use nomad volume validate before submit","Don't pass zero-valued structs; pass nil if unconstrained"],"tags":["csi","validation","capacity"],"backgroundTag":"missing-required-argument","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"}