inancgumus/learngo · error

wrong input: %v (line #%d)

Error message

wrong input: %v (line #%d)

What it means

Pointer-based parse(): the error is stored in p.lerr instead of being returned, and all subsequent parse/update calls become no-ops once lerr is set. This instance fires when a line does not split into exactly two fields; p.lines was already incremented, so the message reports the true 1-based line number.

Source

Thrown at 26-pointers/04-log-parser-pointers/parser.go:48

	p.lines++

	fields := strings.Fields(line)
	if len(fields) != 2 {
		p.lerr = fmt.Errorf("wrong input: %v (line #%d)", fields, p.lines)
		return
	}

	parsed.domain = fields[0]

	var err error

	parsed.visits, err = strconv.Atoi(fields[1])

View on GitHub (pinned to 3c475a78e5)

Solutions

  1. Let main detect p.lerr after parsing and report the offending line, then exit.
  2. Sanitize or skip malformed lines before feeding them to parse.
  3. Fix the log file so every line has a domain and a visits value.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at 26-pointers/04-log-parser-pointers/parser.go:48 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/16a4b195183d50a2. Report an issue: GitHub.