inancgumus/learngo · error

wrong input: %v (line #%d)

Error message

wrong input: %v (line #%d)

What it means

parse() rejects a log line that does not split into exactly two whitespace-separated fields (domain and visits). fields is the []string from strings.Fields; the error embeds the offending fields slice and the line number tracked in p.lines so the user can locate the bad line in the log file.

Source

Thrown at 25-functions/03-refactor-to-funcs/parser.go:41

// parse parses a log line and returns the parsed result with an error
func parse(p parser, line string) (parsed result, err error) {
	fields := strings.Fields(line)
	if len(fields) != 2 {
		err = fmt.Errorf("wrong input: %v (line #%d)", fields, p.lines)
		return
	}

	parsed.domain = fields[0]

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

View on GitHub (pinned to 3c475a78e5)

Solutions

  1. Skip malformed lines and continue parsing the rest of the log, collecting the errors.
  2. Fix the source log line so it has exactly a domain and a numeric visits column.
  3. Halt parsing and report the first offending line with its number, as main does.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at 25-functions/03-refactor-to-funcs/parser.go:41 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/eebd9214c2c8da57. Report an issue: GitHub.