Skip to content

Commit aac1acd

Browse files
Denis Fokindenis-fokin
Denis Fokin
authored andcommitted
Bring back error handling in the Idea plugin #9
1 parent 3c78560 commit aac1acd

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.utbot.intellij.plugin.error
2+
3+
import com.intellij.openapi.application.invokeLater
4+
import com.intellij.openapi.project.Project
5+
import com.intellij.openapi.ui.Messages
6+
7+
fun showErrorDialogLater(project: Project, message: String, title: String) {
8+
invokeLater {
9+
Messages.showErrorDialog(project, message, title)
10+
}
11+
}

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/TestGenerator.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
6262
import org.jetbrains.kotlin.psi.psiUtil.endOffset
6363
import org.jetbrains.kotlin.psi.psiUtil.startOffset
6464
import org.jetbrains.kotlin.scripting.resolve.classId
65+
import org.utbot.intellij.plugin.error.showErrorDialogLater
6566

6667
object TestGenerator {
6768
fun generateTests(model: GenerateTestsModel, testCases: Map<PsiClass, List<UtTestCase>>) {
@@ -268,7 +269,11 @@ object TestGenerator {
268269
SarifReportIdea.createAndSave(model, testCases, generatedTestsCode, sourceFinding)
269270
}
270271
} catch (e: Exception) {
271-
logger.error{ "Cannot save Sarif report via generated tests: error occurred '${e.message}'"}
272+
showErrorDialogLater(
273+
project,
274+
message = "Cannot save Sarif report via generated tests: error occurred '${e.message}'",
275+
title = "Failed to save Sarif report"
276+
)
272277
}
273278

274279
try {
@@ -280,7 +285,11 @@ object TestGenerator {
280285
}
281286
}
282287
} catch (e: Exception) {
283-
logger.error { "Cannot save tests generation report: error occurred '${e.message}'" }
288+
showErrorDialogLater(
289+
project,
290+
message = "Cannot save tests generation report: error occurred '${e.message}'",
291+
title = "Failed to save tests report"
292+
)
284293
}
285294
}
286295

@@ -393,6 +402,10 @@ object TestGenerator {
393402
}
394403

395404
private fun showCreatingClassError(project: Project, testClassName: String) {
396-
logger.error { "Cannot Create Class '$testClassName'" }
405+
showErrorDialogLater(
406+
project,
407+
message = "Cannot Create Class '$testClassName'",
408+
title = "Failed to Create Class"
409+
)
397410
}
398411
}

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/UtTestsDialogProcessor.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import java.nio.file.Paths
4040
import java.util.concurrent.TimeUnit
4141
import mu.KotlinLogging
4242
import org.jetbrains.kotlin.idea.util.module
43+
import org.utbot.intellij.plugin.error.showErrorDialogLater
4344

4445
object UtTestsDialogProcessor {
4546

@@ -165,7 +166,11 @@ object UtTestsDialogProcessor {
165166
}
166167

167168
if (notEmptyCases.isEmpty()) {
168-
logger.error { "Failed to generate unit tests for class $className" }
169+
showErrorDialogLater(
170+
model.project,
171+
errorMessage(className, secondsTimeout),
172+
title = "Failed to generate unit tests for class $className"
173+
)
169174
} else {
170175
testCasesByClass[srcClass] = notEmptyCases
171176
}

0 commit comments

Comments
 (0)