Skip to content

Conversation

@jkschneider
Copy link
Member

@jkschneider jkschneider commented Jan 27, 2026

Summary

  • Updated PatchApplyException messages to include the file path being patched
  • Now uses the existing patchApplyErrorWithHunk message template instead of patchApplyException
  • Provides better context for debugging patch application failures

Problem

When a patch fails to apply, the error message only included the HunkHeader (line start/count info), but not which file was being patched. This made debugging difficult since the same hunk pattern could occur in multiple files within a patch.

Before:

Cannot apply: HunkHeader[1,5->2,6]

After:

Error applying patch in src/main/java/Foo.java, hunk HunkHeader[1,5->2,6]: hunk does not apply to file content

Solution

Changed four exception throws in ApplyCommand.applyText() to use the patchApplyErrorWithHunk message template which accepts the file path as its first parameter:

  1. Hunk out of sequence - When hunks are not properly ordered
  2. Cannot apply hunk - When a hunk with newStartLine=0 can't be applied
  3. Hunk position overlaps - When hunk application position conflicts with previous hunk
  4. Hunk does not apply - When hunk content doesn't match file content

Test plan

  • Code compiles successfully

  • Existing message templates already existed but were unused

  • Fixes moderneinc/customer-requests#1759

When a patch fails to apply, the error message now includes the file path
being patched, making it easier to debug which file caused the failure.
Previously, only the HunkHeader information (line start/count) was shown,
which could be ambiguous when the same pattern exists in multiple files.

Fixes moderneinc/customer-requests#1759
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jan 27, 2026
@jkschneider jkschneider merged commit 3197067 into main Jan 27, 2026
1 check passed
@jkschneider jkschneider deleted the jkschneider/patch-error-include-file branch January 27, 2026 14:10
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants