thanos-io/thanos · error
cannot parse to a valid limit
Error message
cannot parse %q to a valid limit
What it means
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.
Solutions
- Pass limit as a plain non-negative integer
- Remove the limit parameter to disable limiting
Example fix
// before GET /api/v1/labels?limit=1.5 // after GET /api/v1/labels?limit=100
Defensive patterns
Strategy: validation
Validate before calling
function validLimit(s) { return /^-?\d+$/.test(s); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Passing fractional limits, strings with whitespace, or scientific notation; UIs sending placeholder text; scripting errors concatenating wrong variables into the URL.
Understand the failure class
Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.
Related errors
- cannot parse to a valid duration
- limit must be non-negative
- invalid metric metadata limit=
- cannot parse to a valid duration. It overflows int64
- parse federation labels
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/d344494d585b02df.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/api/query/v1.go:1624
return 0, errors.Errorf("cannot parse %q to a valid duration. It overflows int64", s)
}
return time.Duration(ts), nil
}
if d, err := model.ParseDuration(s); err == nil {
return time.Duration(d), nil
}
return 0, errors.Errorf("cannot parse %q to a valid duration", s)
}
// parseLimitParam returning 0 means no limit is to be applied.
func parseLimitParam(s string) (int, error) {
if s == "" {
return 0, nil
}
limit, err := strconv.Atoi(s)
if err != nil {
return 0, errors.Errorf("cannot parse %q to a valid limit", s)
}
if limit < 0 {
return 0, errors.New("limit must be non-negative")
}
return limit, nil
}
// toHintLimit increases the API limit, as returned by parseLimitParam, by 1.
// This allows for emitting warnings when the results are truncated.
func toHintLimit(limit int) int {
// 0 means no limit and avoid int overflow
if limit > 0 && limit < math.MaxInt {
return limit + 1
}
return limit
}
View on GitHub (pinned to 35b8b99117)