{"record":{"id":"bad63ec061bba79e","repo":"plandex-ai/plandex","slug":"failed-to-parse-the-original-content-v","errorCode":null,"errorMessage":"failed to parse the original content: %v","messagePattern":"failed to parse the original content: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/syntax/structured_edits_tree_sitter.go","lineNumber":98,"sourceCode":"\t\t\t// keep indentation for syntax parsing\n\t\t\tcontent := strings.TrimSpace(line)\n\n\t\t\tif removalsByLine[Removal(i+1)] || refsByLine[Reference(i+1)] {\n\t\t\t\tcomment := openingCommentSymbol + \" ref \" + closingCommentSymbol\n\t\t\t\tproposedLines[i] = strings.Replace(line, content, comment, 1)\n\t\t\t}\n\t\t}\n\t}\n\n\tproposedWithNormalizedComments := strings.Join(proposedLines, \"\\n\")\n\tres.Proposed = proposedWithNormalizedComments\n\n\toriginalBytes := []byte(original)\n\tproposedBytes := []byte(proposedWithNormalizedComments)\n\n\toriginalTree, err := parser.ParseCtx(ctx, nil, originalBytes)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse the original content: %v\", err)\n\t}\n\tdefer originalTree.Close()\n\n\tproposedTree, err := parser.ParseCtx(ctx, nil, proposedBytes)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse the proposed content: %v\", err)\n\t}\n\tdefer proposedTree.Close()\n\n\tif verboseLogging {\n\t\tfmt.Printf(\"anchorLines: %v\\n\", anchorLines)\n\t}\n\n\toRes := BuildNodeIndex(originalTree)\n\tpRes := BuildNodeIndex(proposedTree)\n\n\toriginalNodesByLineIndex := oRes.nodesByLine\n\tproposedNodesByLineIndex := pRes.nodesByLine","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/syntax/structured_edits_tree_sitter.go#L80-L116","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nres, err := edits.ApplyChanges(path, original, proposed)\n// after\nif err := syntax.ValidateFile(path, original); err != nil {\n    // fall back to plain string replacement\n    return plainReplace(original, proposed)\n}\nres, err := edits.ApplyChanges(path, original, proposed)","handlingStrategy":"validation","validationCode":"vres, err := syntax.ValidateWithParsers(lang, original, parsers)\nif err != nil || vres == nil || vres.ParseHasError {\n    return fmt.Errorf(\"original not parseable; use plain text edit\")\n}","typeGuard":"func canTreeSitterApply(lang shared.Language, original string, parsers []*syntax.Parser) bool {\n    res, err := syntax.ValidateWithParsers(lang, original, parsers)\n    return err == nil && res != nil && !res.ParseHasError\n}","tryCatchPattern":"res, err := ApplyChanges(path, original, proposed)\nif err != nil && strings.Contains(err.Error(), \"failed to parse the original content\") {\n    return plainTextReplace(original, proposed) // fallback\n}","preventionTips":["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"],"tags":["tree-sitter","apply-edit","parse-error","go"],"backgroundTag":"file-parse-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}