plandex-ai/plandex · warning

invalid line number: %v

Error message

invalid line number: %v

What it means

ExtractLineNumberWithPrefix parses a line number from a text chunk in a streamed response (e.g. `42: some code`). After locating the prefix, it converts the numeric portion with strconv.Atoi; if that conversion fails (the text after the prefix is not a valid integer), it returns this wrapped error. This indicates the streamed content did not match the expected `NNN: text` format.

Source

Thrown at app/shared/streamed_change.go:95

func ExtractLineNumber(line string) (int, error) {
	return ExtractLineNumberWithPrefix(line, "pdx-")
}

func ExtractLineNumberWithPrefix(line, prefix string) (int, error) {
	// Split the line at the first space to isolate the line number
	parts := strings.SplitN(line, " ", 2)

	// Remove the colon from the line number part
	lineNumberStr := strings.TrimSuffix(parts[0], ":")
	lineNumberStr = strings.TrimPrefix(lineNumberStr, prefix)
	if lineNumberStr == "" {
		return 0, fmt.Errorf("no line number found")
	}

	// Convert the line number part to an integer
	lineNumber, err := strconv.Atoi(lineNumberStr)
	if err != nil {
		return 0, fmt.Errorf("invalid line number: %v", err)
	}

	return lineNumber, nil
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the actual input string at the call site and confirm it matches the expected `<digits>: <text>` format before parsing
  2. Fix the upstream stream so chunks are not split mid-token (join chunks before extracting line numbers)
  3. Handle the error gracefully by skipping chunks without a parseable line number instead of propagating it
  4. Check for model/provider changes that alter the line-prefix convention and update the extraction regex accordingly

Example fix

// before
lineNumber, err := ExtractLineNumberWithPrefix(chunk)
if err != nil {
    return err
}
// after
lineNumber, err := ExtractLineNumberWithPrefix(chunk)
if err != nil {
    log.Printf("skipping chunk without line number: %v", err)
    continue
}
Defensive patterns

Strategy: validation

Validate before calling

re := regexp.MustCompile(`^(\d+)\s*:`)
if !re.MatchString(chunk) {
    // skip or handle chunk without a line-number prefix
}

Type guard

func hasLineNumberPrefix(s string) bool {
    i := strings.Index(s, ":")
    if i <= 0 { return false }
    _, err := strconv.Atoi(strings.TrimSpace(s[:i]))
    return err == nil
}

Prevention

When it happens

Trigger: Calling ExtractLineNumberWithPrefix (directly or via ExtractLineNumber or GetLinesWithPrefix) on a string whose prefix, after stripping, is non-numeric — e.g. an empty string, `abc: foo`, `1.5: x`, or output from a model that changed its line-prefix format.

Common situations: Model output format drift where the assistant stops emitting `N: ` prefixes; parsing truncated or partial streamed chunks where the number got split across chunks; parsing human-written text (headings like `Note: ...`) that coincidentally contains a colon.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/cad197ab2fa2ba31. Report an issue: GitHub.