inancgumus/learngo · error
line #%d: %s
Error message
line #%d: %s
What it means
The report parser's Parse method parses each line via parse(line) and, on failure, records the error in p.lerr prefixed with the 1-based line counter p.lines ('line #%d: %s') and returns, stopping further parsing. The stored error is reported after the whole file has been streamed.
Source
Thrown at logparser/testing/report/parser.go:37
lerr error // the last error occurred
}
// New returns a new parsing state.
func New() *Parser {
return &Parser{summary: newSummary()}
}
// Parse parses a log line and adds it to the summary.
func (p *Parser) Parse(line string) {
// if there was an error do not continue
if p.lerr != nil {
return
}
// chain the parser's error to the result's
res, err := parse(line)
if p.lines++; err != nil {
p.lerr = fmt.Errorf("line #%d: %s", p.lines, err)
return
}
p.summary.update(res)
}
// Summarize summarizes the parsing results.
// Only use it after the parsing is done.
func (p *Parser) Summarize() *Summary {
return p.summary
}
// Err returns the last error encountered
func (p *Parser) Err() error {
return p.lerr
}
View on GitHub (pinned to 3c475a78e5)
Solutions
- Fix or remove the line indicated by 'line #N' in the error
- Validate lines before Parse (3 whitespace-separated fields, non-negative integers)
- Decide on a policy: fail-fast (current) vs. collecting all bad lines and reporting a summary
Example fix
// before
if p.lines++; err != nil {
p.lerr = fmt.Errorf("line #%d: %s", p.lines, err)
return
}
// after
if p.lines++; err != nil {
p.skipped++
p.lerr = fmt.Errorf("line #%d: %s", p.lines, err) // keep last; continue parsing
return
} Defensive patterns
Strategy: validation
Validate before calling
for i, line := range lines {
if len(strings.Fields(line)) != 3 {
log.Printf("line %d malformed, skipping", i+1)
continue
}
p.Parse(line)
} Type guard
func isReportLine(line string) bool {
fs := strings.Fields(line)
if len(fs) != 3 { return false }
v, err1 := strconv.Atoi(fs[1]); t, err2 := strconv.Atoi(fs[2])
return err1 == nil && err2 == nil && v >= 0 && t >= 0
} Try / catch
if p.lerr != nil {
log.Fatalf("parsing stopped: %v", p.lerr) // p.lerr already contains 'line #N: ...'
} Prevention
- Validate each line (3 fields, non-negative ints) before Parse
- Decide fail-fast vs. skip-and-report policy up front
- Check p.lerr after the parse loop and surface it to the user
- Keep a rejected-lines list for post-run inspection
When it happens
Trigger: Calling Parse with a line whose field count != 3 (error 33) or whose numeric fields fail field.atoi (error 34); the wrapped message identifies the offending line number.
Common situations: Log lines missing the visits or time-spent column, negative visit counts, non-numeric numbers ('12,000'), or headers/blank lines accidentally fed to the parser.
Related errors
AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02).
Data as JSON: /api/errors/8a387a4c2dea44da.
Report an issue: GitHub.