hashicorp/nomad · error
MaxEntries cannot be negative
Error message
MaxEntries cannot be negative
What it means
This error is returned by ControllerListVolumesRequest.Validate when MaxEntries is negative. MaxEntries caps the number of volume entries returned per page; a negative value is meaningless and likely a caller bug (e.g. a signed-int underflow or an uninitialized variable), so it is rejected locally before the gRPC call.
Source
Thrown at plugins/csi/plugin.go:698
type ControllerListVolumesRequest struct {
MaxEntries int32
StartingToken string
}
func (r *ControllerListVolumesRequest) ToCSIRepresentation() *csipbv1.ListVolumesRequest {
if r == nil {
return nil
}
return &csipbv1.ListVolumesRequest{
MaxEntries: r.MaxEntries,
StartingToken: r.StartingToken,
}
}
func (r *ControllerListVolumesRequest) Validate() error {
if r.MaxEntries < 0 {
return errors.New("MaxEntries cannot be negative")
}
return nil
}
type ControllerListVolumesResponse struct {
Entries []*ListVolumesResponse_Entry
NextToken string
}
func NewListVolumesResponse(resp *csipbv1.ListVolumesResponse) *ControllerListVolumesResponse {
if resp == nil {
return &ControllerListVolumesResponse{}
}
entries := []*ListVolumesResponse_Entry{}
if resp.Entries != nil {
for _, entry := range resp.Entries {
vol := entry.GetVolume()
status := entry.GetStatus()View on GitHub (pinned to 482b49bf1a)
Solutions
- Set MaxEntries to 0 (meaning unspecified/no client-imposed limit per CSI spec) instead of a negative number.
- Clamp page-size computations with a max(0, n) before assigning MaxEntries.
- If pagination is desired, use a small positive value (e.g. 100) and iterate with NextToken.
- Audit the caller for signed arithmetic that can underflow.
Example fix
// before
req := &ControllerListVolumesRequest{MaxEntries: computedSize} // may be -1
// after
if computedSize < 0 { computedSize = 0 }
req := &ControllerListVolumesRequest{MaxEntries: computedSize} Defensive patterns
Strategy: validation
Validate before calling
if req.MaxEntries < 0 {
req.MaxEntries = 0 // 0 = unspecified per CSI spec
} Type guard
func validMaxEntries(r *ControllerListVolumesRequest) bool {
return r != nil && r.MaxEntries >= 0
} Prevention
- Clamp page-size math with max(0, n) before assigning.
- Use 0 (not -1) to mean 'no limit' in CSI requests.
- Keep pagination counters unsigned where possible.
When it happens
Trigger: Calling the list-volumes path with ControllerListVolumesRequest{MaxEntries: -1} — typically from a page-size variable computed as a difference that went negative, or a default set to a signed constant below zero.
Common situations: Pagination math like pageSize := remaining - nextOffset returning a negative; copying a 'no limit' idiom of -1 from another API that rejects it; int truncation from unsigned to signed.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- CSI.ControllerAttachVolume: VolumeID is required
- CSI.ControllerAttachVolume: ClientCSINodeID is required
- CSI.ControllerDetachVolume: VolumeID is required
- CSI.ControllerDetachVolume: ClientCSINodeID is required
- CSI.NodeDetachVolume: PluginID is required
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/4a9e4f5d6e9c29d4.
Report an issue: GitHub.