{"record":{"id":"ec50035c59b12eae","repo":"thanos-io/thanos","slug":"zero-or-negative-query-resolution-step-widths-are","errorCode":null,"errorMessage":"zero or negative query resolution step widths are not accepted. Try a positive integer","messagePattern":"zero or negative query resolution step widths are not accepted\\. Try a positive integer","errorType":"validation","errorClass":"api.ApiError","httpStatus":400,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":788,"sourceCode":"\tif err != nil {\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}, func() {}\n\t}\n\tend, err := parseTime(r.FormValue(\"end\"))\n\tif err != nil {\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}, func() {}\n\t}\n\tif end.Before(start) {\n\t\terr := errors.New(\"end timestamp must not be before start time\")\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}, func() {}\n\t}\n\n\tstep, apiErr := qapi.parseStep(r, qapi.defaultRangeQueryStep, int64(end.Sub(start)/time.Second))\n\tif apiErr != nil {\n\t\treturn nil, nil, apiErr, func() {}\n\t}\n\n\tif step <= 0 {\n\t\terr := errors.New(\"zero or negative query resolution step widths are not accepted. Try a positive integer\")\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}, func() {}\n\t}\n\n\t// For safety, limit the number of returned points per timeseries.\n\t// This is sufficient for 60s resolution for a week or 1h resolution for a year.\n\tif end.Sub(start)/step > 11000 {\n\t\terr := errors.New(\"exceeded maximum resolution of 11,000 points per timeseries. Try decreasing the query resolution (?step=XX)\")\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}, func() {}\n\t}\n\n\tctx := r.Context()\n\tif to := r.FormValue(\"timeout\"); to != \"\" {\n\t\tvar cancel context.CancelFunc\n\t\ttimeout, err := parseDuration(to)\n\t\tif err != nil {\n\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}, func() {}\n\t\t}\n","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L770-L806","documentation":"In queryRange, after the step is resolved (from the `step` parameter or the default), a non-positive step is rejected with HTTP 400 (api.ErrorBadData). A zero or negative step would make point computation impossible, so the API requires a strictly positive duration. Note that parseStep's default of rangeSeconds/250 can itself round down to 0 for sub-second ranges, and an explicit `step=0` or negative value triggers this directly.","triggerScenarios":"Calling /api/v1/query_range with `step=0`, `step=-1m`, or when the step parameter parses to a zero/negative duration; also with a very short range and no step, when the rangeSeconds/250 default computes to 0.","commonSituations":"Clients sending step from a variable that is empty or 0; users entering '0' in a dashboard step field; sub-second query ranges relying on the automatic default step.","solutions":["Pass an explicit positive step such as `step=1s` or `step=15s`.","Validate step > 0 in the client before issuing the request.","Widen the query range (or set an explicit step) so the default rangeSeconds/250 does not compute to 0."],"exampleFix":"// before\nGET /api/v1/query_range?query=up&start=...&end=...&step=0\n// after\nGET /api/v1/query_range?query=up&start=...&end=...&step=15s","handlingStrategy":"validation","validationCode":"const stepMs = parseDurationMs(step); // e.g. '15s' -> 15000\nif (step !== undefined && (!Number.isFinite(stepMs) || stepMs <= 0)) {\n  throw new Error('step must be a positive duration');\n}","typeGuard":null,"tryCatchPattern":"const body = await res.json();\nif (body.status === 'error' && /zero or negative query resolution step/.test(body.error)) {\n  // retry with an explicit positive step such as 1s\n}","preventionTips":["Never send step=0 or negative steps; default to something like 15s when unset.","For very short ranges, set an explicit step since the auto default (range/250) can round to 0.","Clamp computed steps to a minimum of 1s in client-side helpers."],"tags":["http-api","query-range","step","bad-request"],"backgroundTag":"invalid-query-parameter","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}