mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix: handle parsePatch errors in TUI to prevent crashes
Wrap parsePatch calls in try-catch blocks to gracefully handle malformed diffs that can occur when undoing after tool_use/tool_result errors or cancelled prompts. Prevents TUI from crashing with 'Added line count did not match for hunk' error. Fixes #3700
This commit is contained in:
parent
348a333ff6
commit
5184607bac
1 changed files with 69 additions and 60 deletions
|
|
@ -480,6 +480,7 @@ export function Session() {
|
|||
const diffText = s.revert?.diff || ""
|
||||
if (!diffText) return []
|
||||
|
||||
try {
|
||||
const patches = parsePatch(diffText)
|
||||
return patches.map((patch) => {
|
||||
const filename = patch.newFileName || patch.oldFileName || "unknown"
|
||||
|
|
@ -496,6 +497,9 @@ export function Session() {
|
|||
),
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
return []
|
||||
}
|
||||
})()
|
||||
|
||||
return {
|
||||
|
|
@ -1245,6 +1249,8 @@ ToolRegistry.register<typeof EditTool>({
|
|||
const diff = createMemo(() => {
|
||||
const diff = props.metadata.diff ?? props.permission["diff"]
|
||||
if (!diff) return null
|
||||
|
||||
try {
|
||||
const patches = parsePatch(diff)
|
||||
if (patches.length === 0) return null
|
||||
|
||||
|
|
@ -1298,6 +1304,9 @@ ToolRegistry.register<typeof EditTool>({
|
|||
oldContent: oldLines.join("\n"),
|
||||
newContent: newLines.join("\n"),
|
||||
}
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
})
|
||||
|
||||
const code = createMemo(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue