Skip to content

Commit bb8da4c

Browse files
committed
fix(devti): handle file read errors and improve null safety #352
- Improve null safety when accessing virtual files in PlannerResultSummary and DiffLangSketch - Add error handling for file read operations in FileInsCommand - Simplify file creation logic in DiffLangSketch
1 parent 58e5762 commit bb8da4c

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/planner/PlannerResultSummary.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class PlannerResultSummary(
109109
}
110110

111111
override fun onAccept(change: Change) {
112-
val file = change.virtualFile
112+
val file = change.afterRevision?.file?.virtualFile
113113
val content = change.afterRevision?.content ?: change.beforeRevision?.content
114114

115115
runWriteAction {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,14 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S
109109
private fun createDiffPanel(patch: TextFilePatch): SingleFileDiffSketch? {
110110
return when {
111111
patch.beforeName != null -> {
112-
val originFile = myProject.findFile(patch.beforeName!!)
113112
/// if before file is empty, should set new code empty, it should be new file
114-
?: LightVirtualFile(patch.beforeFileName!!, "")
113+
val originFile = myProject.findFile(patch.beforeName!!)
114+
?: LightVirtualFile(patch.beforeName!!, "")
115115
createSingleFileDiffSketch(originFile, patch)
116116
}
117117

118118
patch.afterName != null -> {
119-
val virtualFile = myProject.findFile(patch.afterName!!)
120-
?: LightVirtualFile(patch.afterFileName!!, "")
119+
val virtualFile = myProject.findFile(patch.afterName!!) ?: LightVirtualFile(patch.afterName!!, "")
121120
createSingleFileDiffSketch(virtualFile, patch)
122121
}
123122

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/FileInsCommand.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ class FileInsCommand(private val myProject: Project, private val prop: String) :
4444
}
4545
}
4646

47-
val content = virtualFile?.readText()
47+
val content = try {
48+
virtualFile?.readText()
49+
} catch (e: Exception) {
50+
null
51+
}
52+
4853
if (content == null) {
4954
AutoDevNotifications.warn(myProject, "File not found: $prop")
5055
return "File not found: $prop"

0 commit comments

Comments
 (0)