{"record":{"id":"7b807c0cdc4e6209","repo":"SigNoz/signoz","slug":"offset-and-limit-must-be-greater-than-0","errorCode":null,"errorMessage":"offset and limit must be greater than 0","messagePattern":"offset and limit must be greater than 0","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/query-service/model/alerting.go","lineNumber":164,"sourceCode":"\tRelatedLogsLink   string `json:\"relatedLogsLink\"`\n}\n\ntype QueryRuleStateHistory struct {\n\tStart   int64         `json:\"start\"`\n\tEnd     int64         `json:\"end\"`\n\tState   string        `json:\"state\"`\n\tFilters *v3.FilterSet `json:\"filters\"`\n\tOffset  int64         `json:\"offset\"`\n\tLimit   int64         `json:\"limit\"`\n\tOrder   string        `json:\"order\"`\n}\n\nfunc (r *QueryRuleStateHistory) Validate() error {\n\tif r.Start == 0 || r.End == 0 {\n\t\treturn fmt.Errorf(\"start and end are required\")\n\t}\n\tif r.Offset < 0 || r.Limit < 0 {\n\t\treturn fmt.Errorf(\"offset and limit must be greater than 0\")\n\t}\n\tif r.Order != \"asc\" && r.Order != \"desc\" {\n\t\treturn fmt.Errorf(\"order must be asc or desc\")\n\t}\n\treturn nil\n}\n\ntype RuleStateHistoryContributor struct {\n\tFingerprint       uint64       `json:\"fingerprint\" ch:\"fingerprint\"`\n\tLabels            LabelsString `json:\"labels\" ch:\"labels\"`\n\tCount             uint64       `json:\"count\" ch:\"count\"`\n\tRelatedTracesLink string       `json:\"relatedTracesLink\"`\n\tRelatedLogsLink   string       `json:\"relatedLogsLink\"`\n}\n\ntype RuleStateTransition struct {\n\tRuleID         string     `json:\"ruleID\" ch:\"rule_id\"`\n\tState          AlertState `json:\"state\" ch:\"state\"`","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/model/alerting.go#L146-L182","documentation":"QueryRuleStateHistory.Validate rejects negative Offset or Limit values for alerting rule state history pagination. The message text says 'greater than 0' but the code only forbids negative values; 0 is allowed.","triggerScenarios":"Passing offset=-10 or limit=-1 (negative numbers) as query params to the rule state history endpoint, often via URL manipulation or int parsing of '-'.","commonSituations":"Manually edited URLs; client-side pagination math producing negative offsets at the first page; typo'd defaults.","solutions":["Clamp offset and limit to >= 0 before sending","Fix client pagination arithmetic so offsets never go negative (use max(0, computed))","Note 0 is valid; only negatives are rejected"],"exampleFix":"// before\nGET /api/rules/<id>/state_history?offset=-20&start=..&end=..\n\n// after\nGET /api/rules/<id>/state_history?offset=0&start=..&end=..","handlingStrategy":"validation","validationCode":"if r.Offset < 0 { r.Offset = 0 }\nif r.Limit < 0 { r.Limit = 0 }","typeGuard":"func nonNegativePagination(offset, limit int64) bool { return offset >= 0 && limit >= 0 }","tryCatchPattern":null,"preventionTips":["Clamp pagination math client-side","Never construct pagination values from unvalidated user input"],"tags":["signoz","alerting","pagination","validation"],"backgroundTag":"invalid-query-parameter","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}