inancgumus/learngo · error
wrong input: %q (line #%d)
Error message
wrong input: %q (line #%d)
What it means
Exercise variant of parse(): rejects the visits column when Atoi fails or yields a negative number; %q shows the offending token and p.lines identifies the log line. The error propagates to main, which terminates the program.
Source
Thrown at 26-pointers/exercises/05-log-parser/parser.go:49
parsed.domain = fields[0]
parsed.visits, err = strconv.Atoi(fields[1])
if parsed.visits < 0 || err != nil {
err = fmt.Errorf("wrong input: %q (line #%d)", fields[1], p.lines)
return
}View on GitHub (pinned to 3c475a78e5)
Solutions
- Validate the visits token before parsing each line.
- Skip invalid rows and aggregate the valid ones.
- Fix the log so visits are non-negative integers.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at 26-pointers/exercises/05-log-parser/parser.go:49 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02).
Data as JSON: /api/errors/bf366c8d4b4944a9.
Report an issue: GitHub.