Skip to content

Commit b19ca92

Browse files
committed
fix(devins-lang): improve patch command error handling and UI feedback
- Add null check for parsePatches result- Show warning notification when patch parsing fails - Replace logger warnings with UI notifications for better user feedback - Improve error messages for empty and invalid patches
1 parent 4b19877 commit b19ca92

File tree

1 file changed

+12
-9
lines changed
  • exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package cc.unitmesh.devti.language.compiler.exec
22

3+
import cc.unitmesh.devti.AutoDevNotifications
34
import cc.unitmesh.devti.devin.InsCommand
45
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
56
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
67
import cc.unitmesh.devti.sketch.AutoSketchMode
7-
import cc.unitmesh.devti.sketch.ui.patch.SingleFileDiffSketch
88
import cc.unitmesh.devti.sketch.ui.patch.readText
99
import cc.unitmesh.devti.sketch.ui.patch.writeText
1010
import com.intellij.openapi.diagnostic.logger
@@ -19,13 +19,15 @@ import com.intellij.openapi.util.Disposer
1919
class PatchInsCommand(val myProject: Project, val prop: String, val codeContent: String) : InsCommand {
2020
override val commandName: BuiltinCommand = BuiltinCommand.PATCH
2121

22-
private val logger = logger<PatchInsCommand>()
23-
2422
override suspend fun execute(): String? {
25-
2623
val filePatches = parsePatches(codeContent)
24+
if (filePatches == null) {
25+
AutoDevNotifications.warn(myProject, "Failed to parse patches from content")
26+
return "$DEVINS_ERROR: Failed to parse patches"
27+
}
28+
2729
if (filePatches.isEmpty()) {
28-
logger.warn("No patches found in content")
30+
AutoDevNotifications.warn(myProject, "No patches found in content")
2931
return "$DEVINS_ERROR: No patches found"
3032
}
3133

@@ -63,12 +65,13 @@ class PatchInsCommand(val myProject: Project, val prop: String, val codeContent:
6365
return result
6466
}
6567

66-
private fun parsePatches(content: String): List<TextFilePatch> {
68+
private fun parsePatches(content: String): List<TextFilePatch>? {
6769
return try {
68-
PatchReader(content).apply { parseAllPatches() }.textPatches
70+
PatchReader(content).apply {
71+
parseAllPatches()
72+
}.textPatches
6973
} catch (e: Exception) {
70-
logger.error("Failed to parse patches", e)
71-
emptyList()
74+
null
7275
}
7376
}
7477
}

0 commit comments

Comments
 (0)