Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 10, 2025

Fixes #6905

Problem

The application was throwing a runtime error "v.content.match is not a function" when attempting to apply diffs. This occurred when diffItem.content was not a string (could be null, undefined, or another type), but the code was calling .match() on it without type checking.

Solution

Added a type check to ensure diffItem.content is a string before calling .match() method on it. This prevents the runtime error and allows the diff application to handle non-string content gracefully.

Changes

  • Added typeof diffItem.content === 'string' check in src/core/tools/multiApplyDiffTool.ts before calling .match()
  • Created comprehensive test suite in src/core/tools/__tests__/multiApplyDiffTool.spec.ts to verify the fix handles:
    • undefined content
    • null content
    • numeric content
    • mixed content types in diff arrays
    • proper counting of SEARCH blocks for valid strings

Testing

  • All new tests pass ✅
  • All existing tests pass with no regression ✅
  • Linting and type checking pass ✅

Important

Adds type check in applyDiffTool() to prevent runtime errors when diffItem.content is not a string, with comprehensive tests for various content types.

  • Behavior:
    • Adds typeof diffItem.content === 'string' check in applyDiffTool() in multiApplyDiffTool.ts to prevent runtime errors when diffItem.content is not a string.
    • Handles non-string diffItem.content gracefully by skipping invalid entries.
  • Testing:
    • Adds tests in multiApplyDiffTool.spec.ts to verify handling of undefined, null, numeric, and mixed content types.
    • Tests ensure proper counting of SEARCH blocks for valid strings.
    • All new and existing tests pass without regression.

This description was created by Ellipsis for 55f0ab1. You can customize this summary. It will automatically update as commits are pushed.

Fixes #6905 - Error during diff application "v.content.match is not a function"

- Added type check to ensure diffItem.content is a string before calling .match()
- Added comprehensive tests for handling non-string content values
- Prevents runtime errors when content is null, undefined, or other non-string types
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 10, 2025 16:43
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Aug 10, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 10, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.

const searchBlocks = (diffItem.content.match(/<<<<<<< SEARCH/g) || []).length
totalSearchBlocks += searchBlocks
// Ensure content is a string before calling match
if (typeof diffItem.content === "string") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good defensive programming here! Though I wonder - should we also add a similar type check in the legacy applyDiffTool.ts at line 234? While it's currently protected by earlier validation, adding the same defensive check would ensure consistency and future-proof the code.

Also, is there a reason we're not checking for the same issue in the earlier loop around line 420 where we process diff items?

@roomote roomote bot mentioned this pull request Aug 10, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 12, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 12, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

It would be good to find out why this tool is returning content as something other than a string.

@samhvw8

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Aug 14, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 14, 2025
daniel-lxs and others added 4 commits August 14, 2025 17:33
- Move type check to where content is first extracted from XML
- Remove redundant check since content is now guaranteed to be string
- Add test for early content validation
@mrubens mrubens merged commit 0d0bba2 into main Aug 15, 2025
10 checks passed
@mrubens mrubens deleted the fix/issue-6905-diff-content-match-error branch August 15, 2025 00:05
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 15, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Aug 15, 2025
fxcl added a commit to tameslabs/Roo-Cline that referenced this pull request Aug 16, 2025
* main: (70 commits)
  fix: use native Ollama API instead of OpenAI compatibility layer (RooCodeInc#7137)
  feat: add support for OpenAI gpt-5-chat-latest model (RooCodeInc#7058)
  Make enhance with task history default to true (RooCodeInc#7140)
  Bump cloud version to 0.16.0 (RooCodeInc#7135)
  Release: v1.51.0 (RooCodeInc#7130)
  Add an API for resuming tasks by ID (RooCodeInc#7122)
  Add support for task page event population (RooCodeInc#7117)
  fix: add type check before calling .match() on diffItem.content (RooCodeInc#6905) (RooCodeInc#6906)
  Fix: Enable save button for provider dropdown and checkbox changes (RooCodeInc#7113)
  fix: Use cline.cwd as primary source for workspace path in codebaseSearchTool (RooCodeInc#6902)
  Hotfix multiple folder workspace checkpoint (RooCodeInc#6903)
  fix: prevent XML entity decoding in diff tools (RooCodeInc#7107) (RooCodeInc#7108)
  Refactor task execution system: improve call stack management (RooCodeInc#7035)
  Changeset version bump (RooCodeInc#7104)
  feat(web): fill missing SEO-related values (RooCodeInc#7096)
  Update contributors list (RooCodeInc#6883)
  Release v3.25.15 (RooCodeInc#7103)
  fix: add /evals page to sitemap generation (RooCodeInc#7102)
  feat: implement sitemap generation in TypeScript and remove XML file (RooCodeInc#6206)
  fix: reset condensing state when switching tasks (RooCodeInc#6922)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Error during diff application

5 participants