{"record":{"id":"4a9e4f5d6e9c29d4","repo":"hashicorp/nomad","slug":"maxentries-cannot-be-negative","errorCode":null,"errorMessage":"MaxEntries cannot be negative","messagePattern":"MaxEntries cannot be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/csi/plugin.go","lineNumber":698,"sourceCode":"\ntype ControllerListVolumesRequest struct {\n\tMaxEntries    int32\n\tStartingToken string\n}\n\nfunc (r *ControllerListVolumesRequest) ToCSIRepresentation() *csipbv1.ListVolumesRequest {\n\tif r == nil {\n\t\treturn nil\n\t}\n\treturn &csipbv1.ListVolumesRequest{\n\t\tMaxEntries:    r.MaxEntries,\n\t\tStartingToken: r.StartingToken,\n\t}\n}\n\nfunc (r *ControllerListVolumesRequest) Validate() error {\n\tif r.MaxEntries < 0 {\n\t\treturn errors.New(\"MaxEntries cannot be negative\")\n\t}\n\treturn nil\n}\n\ntype ControllerListVolumesResponse struct {\n\tEntries   []*ListVolumesResponse_Entry\n\tNextToken string\n}\n\nfunc NewListVolumesResponse(resp *csipbv1.ListVolumesResponse) *ControllerListVolumesResponse {\n\tif resp == nil {\n\t\treturn &ControllerListVolumesResponse{}\n\t}\n\tentries := []*ListVolumesResponse_Entry{}\n\tif resp.Entries != nil {\n\t\tfor _, entry := range resp.Entries {\n\t\t\tvol := entry.GetVolume()\n\t\t\tstatus := entry.GetStatus()","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/plugins/csi/plugin.go#L680-L716","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nreq := &ControllerListVolumesRequest{MaxEntries: computedSize} // may be -1\n// after\nif computedSize < 0 { computedSize = 0 }\nreq := &ControllerListVolumesRequest{MaxEntries: computedSize}","handlingStrategy":"validation","validationCode":"if req.MaxEntries < 0 {\n\treq.MaxEntries = 0 // 0 = unspecified per CSI spec\n}","typeGuard":"func validMaxEntries(r *ControllerListVolumesRequest) bool {\n\treturn r != nil && r.MaxEntries >= 0\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["csi","validation","pagination","storage"],"backgroundTag":"invalid-argument-value","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"}