inancgumus/learngo · error
wrong input: %q (line #%d)
Error message
wrong input: %q (line #%d)
What it means
In v4's Parse, after fields = strings.Fields(line), the second field is converted with strconv.Atoi. If Atoi fails or the visits count is negative, Parse stores 'wrong input: %q (line #%d)' (quoting the visits token and line number) in p.lerr and returns; the result for that line is not passed to update.
Source
Thrown at logparser/v4/parser.go:58
if p.lerr != nil {
return
}
p.lines++
fields := strings.Fields(line)
if len(fields) != 2 {
p.lerr = fmt.Errorf("wrong input: %v (line #%d)", fields, p.lines)
return
}
var err error
r.domain = fields[0]
r.visits, err = strconv.Atoi(fields[1])
if r.visits < 0 || err != nil {
p.lerr = fmt.Errorf("wrong input: %q (line #%d)", fields[1], p.lines)
}
return
}
// update updates all the parsing results using the given parsing result
func update(p *parser, r result) {
if p.lerr != nil {
return
}
// Collect the unique domains
if _, ok := p.sum[r.domain]; !ok {
p.domains = append(p.domains, r.domain)
}
// Keep track of total and per domain visits
p.total += r.visits
View on GitHub (pinned to 3c475a78e5)
Solutions
- Fix the offending value in the input log
- Pre-validate the visits token as a non-negative integer
- Separate the 'not a number' and 'negative' cases for clearer diagnostics
Example fix
// before
if r.visits < 0 || err != nil {
p.lerr = fmt.Errorf("wrong input: %q (line #%d)", fields[1], p.lines)
}
// after
if err != nil {
p.lerr = fmt.Errorf("line #%d: visits %q is not a number", p.lines, fields[1])
} else if r.visits < 0 {
p.lerr = fmt.Errorf("line #%d: visits %d is negative", p.lines, r.visits)
} Defensive patterns
Strategy: validation
Validate before calling
var countRe = regexp.MustCompile(`^\d+$`)
fs := strings.Fields(line)
if len(fs) == 2 && !countRe.MatchString(fs[1]) {
continue // skip non-numeric visits before Parse
} Type guard
func isNonNegInt(s string) bool {
n, err := strconv.Atoi(s)
return err == nil && n >= 0
} Try / catch
if p.lerr != nil {
var ne *strconv.NumError
if errors.As(p.lerr, &ne) { /* not always wrapped; inspect message */ }
log.Fatalf("parse stopped: %v", p.lerr)
} Prevention
- Validate the visits token before feeding the line to Parse
- Split negative vs. non-numeric handling for clearer errors
- Check p.lerr after parsing and report the line number
- Normalize locale-formatted numbers upstream
When it happens
Trigger: A line whose visits column is negative ('example.com -1') or unparseable ('example.com 12x') during v4 Parse.
Common situations: Negative deltas from upstream aggregation bugs, numbers with units or separators, typos, or locale-formatted numbers ('1.000').
Related errors
- incorrect %s: %q
- wrong input: %q (line #%d)
- wrong input: %v (line #%d)
- Please provide a valid number
- line %d: %v
AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02).
Data as JSON: /api/errors/430c4f8e5e417602.
Report an issue: GitHub.