inancgumus/learngo · error
wrong number of fields %q
Error message
wrong number of fields %q
What it means
parseFields enforces the fixed log schema of fieldsLength (4) columns: domain, page, visits, uniques. When strings.Fields yields a different count — extra whitespace-separated tokens or missing columns — it returns this error with the offending fields slice quoted instead of a record. The %q on a []string prints like ["domain" "page" ...].
Source
Thrown at logparser/functional/result.go:38
// parseFields parses and returns the parsing result
func parseFields(line string) (r result, err error) {
fields := strings.Fields(line)
if len(fields) != fieldsLength {
return r, fmt.Errorf("wrong number of fields %q", fields)
}
r.domain = fields[0]
r.page = fields[1]
f := new(field)
r.visits = f.uatoi("visits", fields[2])
r.uniques = f.uatoi("uniques", fields[3])
return r, f.err
}View on GitHub (pinned to 3c475a78e5)
Solutions
- Skip the malformed line and continue parsing the remaining log.
- Fix the log line so it has exactly four columns: domain page visits uniques.
- Log the offending line with its number for later correction of the input data.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at logparser/functional/result.go:38 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/944fdb682dc996c4.
Report an issue: GitHub.