plandex-ai/plandex · error
failed to parse the original content: %v
Error message
failed to parse the original content: %v
What it means
ExecApplyTreeSitter applies a proposed edit by parsing both the original and the edited (comment-normalized) content with tree-sitter and then aligning the trees. Before any comparison it parses the original source; a ParseCtx failure here is wrapped as 'failed to parse the original content: %v'. Called by ApplyChanges when executing structured (tree-sitter) edits.
Source
Thrown at app/server/syntax/structured_edits_tree_sitter.go:98
// keep indentation for syntax parsing
content := strings.TrimSpace(line)
if removalsByLine[Removal(i+1)] || refsByLine[Reference(i+1)] {
comment := openingCommentSymbol + " ref " + closingCommentSymbol
proposedLines[i] = strings.Replace(line, content, comment, 1)
}
}
}
proposedWithNormalizedComments := strings.Join(proposedLines, "\n")
res.Proposed = proposedWithNormalizedComments
originalBytes := []byte(original)
proposedBytes := []byte(proposedWithNormalizedComments)
originalTree, err := parser.ParseCtx(ctx, nil, originalBytes)
if err != nil {
return nil, fmt.Errorf("failed to parse the original content: %v", err)
}
defer originalTree.Close()
proposedTree, err := parser.ParseCtx(ctx, nil, proposedBytes)
if err != nil {
return nil, fmt.Errorf("failed to parse the proposed content: %v", err)
}
defer proposedTree.Close()
if verboseLogging {
fmt.Printf("anchorLines: %v\n", anchorLines)
}
oRes := BuildNodeIndex(originalTree)
pRes := BuildNodeIndex(proposedTree)
originalNodesByLineIndex := oRes.nodesByLine
proposedNodesByLineIndex := pRes.nodesByLineView on GitHub (pinned to e2d772072e)
Solutions
- Fix the syntax errors in the original file before applying tree-sitter edits
- Verify the correct parser/language is being selected for the file path
- Fall back to a plain (non-tree-sitter) text replacement for files that won't parse
- Check the wrapped '%v' cause for cancellation/operation-limit and adjust the context/limits
Example fix
// before
res, err := edits.ApplyChanges(path, original, proposed)
// after
if err := syntax.ValidateFile(path, original); err != nil {
// fall back to plain string replacement
return plainReplace(original, proposed)
}
res, err := edits.ApplyChanges(path, original, proposed) Defensive patterns
Strategy: validation
Validate before calling
vres, err := syntax.ValidateWithParsers(lang, original, parsers)
if err != nil || vres == nil || vres.ParseHasError {
return fmt.Errorf("original not parseable; use plain text edit")
} Type guard
func canTreeSitterApply(lang shared.Language, original string, parsers []*syntax.Parser) bool {
res, err := syntax.ValidateWithParsers(lang, original, parsers)
return err == nil && res != nil && !res.ParseHasError
} Try / catch
res, err := ApplyChanges(path, original, proposed)
if err != nil && strings.Contains(err.Error(), "failed to parse the original content") {
return plainTextReplace(original, proposed) // fallback
} Prevention
- Validate the original file before choosing tree-sitter edits
- Keep the language detection consistent with file content
- Avoid applying edits to files concurrently modified elsewhere
- Provide a plain-text edit fallback for unparseable files
When it happens
Trigger: ApplyChanges → ExecApplyTreeSitter is invoked with an original file whose content fails to parse with the selected parser — e.g. the file contains syntax errors, is empty, or the wrong parser/language was chosen for it.
Common situations: Applying an edit to a file that was already syntactically broken; language detection mismatch (file edited under a different grammar than its content); truncated or concurrently-modified file content; context cancelled mid-parse.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse the proposed content: %v
- failed to parse the content: %v
- error mapping file %s: %v
- failed to parse file: %v
- failed to parse the content with fallback parser: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/bad63ec061bba79e.
Report an issue: GitHub.