Skip to content

Commit 153b69f

Browse files
committed
fix(devti): handle patch parsing exceptions
- Add exception handling when parsing text patches - Log warning message if patch parsing fails - Initialize filePatches with an empty list if parsing fails
1 parent 7b4ae3e commit 153b69f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/patch/DiffLangSketch.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.intellij.openapi.application.ApplicationManager
1111
import com.intellij.openapi.command.CommandProcessor
1212
import com.intellij.openapi.command.UndoConfirmationPolicy
1313
import com.intellij.openapi.command.undo.UndoManager
14+
import com.intellij.openapi.diagnostic.logger
1415
import com.intellij.openapi.diff.impl.patch.PatchReader
1516
import com.intellij.openapi.diff.impl.patch.TextFilePatch
1617
import com.intellij.openapi.editor.Editor
@@ -46,7 +47,12 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S
4647
null
4748
}
4849
}
49-
private val filePatches: MutableList<TextFilePatch> = myReader?.textPatches ?: mutableListOf()
50+
private val filePatches: MutableList<TextFilePatch> = try {
51+
myReader?.textPatches
52+
} catch (e: Exception) {
53+
logger<DiffLangSketch>().warn("Failed to parse patch: ${e.message}")
54+
mutableListOf()
55+
} ?: mutableListOf()
5056

5157
init {
5258
if (filePatches.size > 1 || filePatches.any { it.beforeName == null }) {

0 commit comments

Comments
 (0)