plandex-ai/plandex · error

error extracting line number from first line: %v

Error message

error extracting line number from first line: %v

What it means

After the 'pdx-' prefix check passes, the code extracts the line number from the first line via shared.ExtractLineNumberWithPrefix. This error wraps any failure from that parser (e.g. 'pdx-' present but no valid integer follows).

Source

Thrown at app/server/model/plan/build_validate_and_fix.go:406

		if !strings.HasPrefix(old, "pdx-") {
			log.Printf("Old content does not have a line number prefix for first line")
			return buildValidateResult{valid: false, updated: updated}, fmt.Errorf("old content does not have a line number prefix for first line")
		}

		oldLines := strings.Split(old, "\n")

		var lastLine string
		var lastLineNum int
		firstLine := oldLines[0]
		if len(oldLines) > 1 {
			lastLine = oldLines[len(oldLines)-1]
		}

		firstLineNum, err := shared.ExtractLineNumberWithPrefix(firstLine, "pdx-")
		if err != nil {
			log.Printf("Error extracting line number from first line: %v", err)
			return buildValidateResult{valid: false, updated: updated}, fmt.Errorf("error extracting line number from first line: %v", err)
		}

		if lastLine != "" {
			lastLineNum, err = shared.ExtractLineNumberWithPrefix(lastLine, "pdx-")
			if err != nil {
				log.Printf("Error extracting line number from last line: %v", err)
				return buildValidateResult{valid: false, updated: updated}, fmt.Errorf("error extracting line number from last line: %v", err)
			}
		}

		if lastLineNum == 0 {
			if !(firstLineNum > 0 && firstLineNum <= len(originalFileLines)) {
				log.Printf("Invalid line number for first line: %d", firstLineNum)
				return buildValidateResult{valid: false, updated: updated}, fmt.Errorf("invalid line number for first line: %d", firstLineNum)
			}
			old = originalFileLines[firstLineNum-1]
		} else {
			if !(firstLineNum > 0 && firstLineNum <= len(originalFileLines) && lastLineNum > firstLineNum && lastLineNum <= len(originalFileLines)) {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Retry the request so the model re-emits the old block with a valid numeric prefix
  2. Validate the model's old-block formatting earlier and fail fast with a clearer retry message
  3. Consider more lenient parsing that tolerates trailing garbage after the number

Example fix

// before
firstLine = "pdx-"  // no number
// after
firstLine = "pdx-42 func main() {}"
Defensive patterns

Strategy: validation

Validate before calling

if _, err := shared.ExtractLineNumberWithPrefix(firstLine, "pdx-"); err != nil {
    return fmt.Errorf("first line number unparseable: %v", err)
}

Type guard

func parseLineNumber(line, prefix string) (int, bool) {
    n, err := shared.ExtractLineNumberWithPrefix(line, prefix)
    return n, err == nil && n > 0
}

Prevention

When it happens

Trigger: First line looks like 'pdx-' or 'pdx-abc' — prefix present but the number cannot be parsed.

Common situations: Model emits truncated or malformed prefixes such as 'pdx- ' or 'pdx-12abc' when it loses track of line numbering on large files.

Related errors


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