Skip to content

Commit 6c0eb94

Browse files
committed
fix(diff): handle VcsException and log diff before error #51
The `DiffSimplifier` class now includes a logger to capture any errors that occur during the diff calculation process. If an error is thrown, the original diff is logged before the exception is re-thrown, providing more context for debugging purposes.
1 parent eaae8b9 commit 6c0eb94

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/kotlin/cc/unitmesh/devti/vcs/DiffSimplifier.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.devti.vcs
22

33
import com.intellij.openapi.components.Service
4+
import com.intellij.openapi.diagnostic.logger
45
import com.intellij.openapi.diff.impl.patch.IdeaTextPatchBuilder
56
import com.intellij.openapi.diff.impl.patch.UnifiedDiffWriter
67
import com.intellij.openapi.project.Project
@@ -16,6 +17,8 @@ import kotlin.math.min
1617

1718
@Service(Service.Level.PROJECT)
1819
class DiffSimplifier(val project: Project) {
20+
private val logger = logger<DiffSimplifier>()
21+
1922
/**
2023
* Simplifies the given list of changes and returns the resulting diff as a string.
2124
*
@@ -25,6 +28,8 @@ class DiffSimplifier(val project: Project) {
2528
* @throws RuntimeException if the project base path is null or if there is an error calculating the diff.
2629
*/
2730
fun simplify(changes: List<Change>, ignoreFilePatterns: List<PathMatcher>): String {
31+
var originChanges: String = ""
32+
2833
try {
2934
val writer = StringWriter()
3035
val basePath = project.basePath ?: throw RuntimeException("Project base path is null.")
@@ -66,8 +71,13 @@ class DiffSimplifier(val project: Project) {
6671
emptyList()
6772
)
6873

69-
return postProcess(writer.toString())
74+
originChanges = writer.toString()
75+
return postProcess(originChanges)
7076
} catch (e: VcsException) {
77+
if (originChanges.isNotEmpty()) {
78+
logger.info("Error calculating diff: $originChanges", e)
79+
}
80+
7181
throw RuntimeException("Error calculating diff: ${e.message}", e)
7282
}
7383
}

0 commit comments

Comments
 (0)