{"record":{"id":"d344494d585b02df","repo":"thanos-io/thanos","slug":"cannot-parse-q-to-a-valid-limit","errorCode":null,"errorMessage":"cannot parse %q to a valid limit","messagePattern":"cannot parse %q to a valid limit","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1624,"sourceCode":"\t\t\treturn 0, errors.Errorf(\"cannot parse %q to a valid duration. It overflows int64\", s)\n\t\t}\n\t\treturn time.Duration(ts), nil\n\t}\n\tif d, err := model.ParseDuration(s); err == nil {\n\t\treturn time.Duration(d), nil\n\t}\n\treturn 0, errors.Errorf(\"cannot parse %q to a valid duration\", s)\n}\n\n// parseLimitParam returning 0 means no limit is to be applied.\nfunc parseLimitParam(s string) (int, error) {\n\tif s == \"\" {\n\t\treturn 0, nil\n\t}\n\n\tlimit, err := strconv.Atoi(s)\n\tif err != nil {\n\t\treturn 0, errors.Errorf(\"cannot parse %q to a valid limit\", s)\n\t}\n\tif limit < 0 {\n\t\treturn 0, errors.New(\"limit must be non-negative\")\n\t}\n\n\treturn limit, nil\n}\n\n// toHintLimit increases the API limit, as returned by parseLimitParam, by 1.\n// This allows for emitting warnings when the results are truncated.\nfunc toHintLimit(limit int) int {\n\t// 0 means no limit and avoid int overflow\n\tif limit > 0 && limit < math.MaxInt {\n\t\treturn limit + 1\n\t}\n\treturn limit\n}\n","sourceCodeStart":1606,"sourceCodeEnd":1642,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1606-L1642","documentation":"Wraps strconv.Atoi in parseLimitParam: the query API limit parameter (e.g. series/label limit) is non-empty but not a base-10 integer. The offending raw string is quoted in the message; the caller rejects the request as bad data.","triggerScenarios":"Calling an endpoint honoring parseLimitParam (e.g. /api/v1/labels, /api/v1/series) with `?limit=ten`, `limit=1.5`, or `limit=`-adjacent garbage that is non-empty but non-numeric.","commonSituations":"Passing fractional limits, strings with whitespace, or scientific notation; UIs sending placeholder text; scripting errors concatenating wrong variables into the URL.","solutions":["Pass limit as a plain non-negative integer","Remove the limit parameter to disable limiting"],"exampleFix":"// before\nGET /api/v1/labels?limit=1.5\n// after\nGET /api/v1/labels?limit=100","handlingStrategy":"validation","validationCode":"function validLimit(s) { return /^-?\\d+$/.test(s); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Send limits as plain base-10 integers.","Omit the param instead of sending empty/garbage values.","Validate user-supplied limits in the UI before request."],"tags":["limit","bad-request","query-api","parsing"],"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"}