kataras/iris · error
redirect match: status code digits: %s: %v
Error message
redirect match: status code digits: %s: %v
What it means
After confirming the code field is all digits, parseRedirectMatchLine still calls strconv.Atoi as a defensive second check. If Atoi fails (e.g. the digits overflow int), the parse fails with this error wrapping the strconv error. It is the fallback arm of the digit validation and rarely fires because the digit loop already ran.
Source
Thrown at middleware/rewrite/rewrite.go:299
func parseRedirectMatchLine(s string) (*redirectMatch, error) {
parts := strings.Split(strings.TrimSpace(s), " ")
if len(parts) != 3 {
return nil, fmt.Errorf("redirect match: invalid line: %s", s)
}
codeStr, pattern, target := parts[0], parts[1], parts[2]
for i, ch := range codeStr {
if !isDigit(ch) {
return nil, fmt.Errorf("redirect match: status code digits: %s [%d:%c]", codeStr, i, ch)
}
}
code, err := strconv.Atoi(codeStr)
if err != nil {
// this should not happen, we check abt digit
// and correctly position the error too but handle it.
return nil, fmt.Errorf("redirect match: status code digits: %s: %v", codeStr, err)
}
regex := regexp.MustCompile(pattern)
if regex.MatchString(target) {
return nil, fmt.Errorf("redirect match: loop detected: pattern: %s vs target: %s", pattern, target)
}
v := &redirectMatch{
code: code,
pattern: regex,
target: target,
noRedirect: code <= 0,
isRelativePattern: pattern[0] == '/', // search by path.
}
return v, nil
}
View on GitHub (pinned to 7bedaf55a0)
Solutions
- Shorten the code field to a valid HTTP status code (100–599).
- Ensure the code field is the actual status code, not a timestamp or ID accidentally placed first.
- Keep the line format strictly 'CODE PATTERN TARGET' so digits land in the right slot.
Example fix
// before
rewrite.New([]rewrite.RedirectMatchLine{"99999999999999999999 /old /new"})
// after
rewrite.New([]rewrite.RedirectMatchLine{"302 /old /new"}) Defensive patterns
Strategy: validation
Validate before calling
code, err := strconv.Atoi(strings.Fields(line)[0])
if err != nil || code < 100 || code > 599 {
return fmt.Errorf("invalid status code in redirect line %q", line)
} Try / catch
if _, err := rewrite.New(lines); err != nil {
log.Fatalf("redirect line rejected: %v", err) // includes strconv detail
} Prevention
- Restrict code fields to real HTTP status codes (100–599).
- Never paste long numeric IDs into the code position.
- Validate configs with strconv.Atoi in a pre-flight test.
When it happens
Trigger: A redirect line whose code field is all digits but not convertible by strconv.Atoi — practically only a numeric string exceeding platform int range (e.g. '99999999999999999999 /old /new').
Common situations: Pasting a very long numeric field into the code position, or machine-generated configs with corrupted numeric fields.
Related errors
- redirect match: status code digits: %s [%d:%c]
- redirect match: loop detected: pattern: %s vs target: %s
- multipart related: next part: %w
- redirect match: invalid line: %s
- option: %s: expected key value separated by '='
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/3119e39bb0f1c673.
Report an issue: GitHub.