Skip to content

Commit 0cd223f

Browse files
committed
fix(devti): handle file read errors in SingleFileDiffSketch #352
- Add error handling when reading file content to prevent application crashes - Log the error message and use an empty string as a fallback value
1 parent 0bce53e commit 0cd223f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ class SingleFileDiffSketch(
5858
private val myHeaderPanel: JPanel = JPanel(BorderLayout())
5959
private var patchActionPanel: JPanel? = null
6060
private val oldCode = if (currentFile.isValid && currentFile.exists()) {
61-
currentFile.readText()
61+
try {
62+
currentFile.readText()
63+
} catch (e: IOException) {
64+
logger<SingleFileDiffSketch>().warn("Failed to read file: ${currentFile.path}", e)
65+
""
66+
}
6267
} else ""
6368

6469
private var appliedPatch = try {

0 commit comments

Comments
 (0)