From 7e254da4a7d191e454a3e239eb3eb9e1a0a20603 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Mon, 23 May 2022 12:23:27 +0300 Subject: [PATCH] Bring back error handling in the Idea plugin #9 --- .../utbot/intellij/plugin/error/ErrorUtils.kt | 11 +++++++++++ .../plugin/generator/TestGenerator.kt | 19 ++++++++++++++++--- .../plugin/ui/UtTestsDialogProcessor.kt | 7 ++++++- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/error/ErrorUtils.kt diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/error/ErrorUtils.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/error/ErrorUtils.kt new file mode 100644 index 0000000000..1fe7945adb --- /dev/null +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/error/ErrorUtils.kt @@ -0,0 +1,11 @@ +package org.utbot.intellij.plugin.error + +import com.intellij.openapi.application.invokeLater +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.Messages + +fun showErrorDialogLater(project: Project, message: String, title: String) { + invokeLater { + Messages.showErrorDialog(project, message, title) + } +} \ No newline at end of file diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/TestGenerator.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/TestGenerator.kt index 73affbd1cd..581c27f24c 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/TestGenerator.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/TestGenerator.kt @@ -62,6 +62,7 @@ import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.scripting.resolve.classId +import org.utbot.intellij.plugin.error.showErrorDialogLater object TestGenerator { fun generateTests(model: GenerateTestsModel, testCases: Map>) { @@ -268,7 +269,11 @@ object TestGenerator { SarifReportIdea.createAndSave(model, testCases, generatedTestsCode, sourceFinding) } } catch (e: Exception) { - logger.error{ "Cannot save Sarif report via generated tests: error occurred '${e.message}'"} + showErrorDialogLater( + project, + message = "Cannot save Sarif report via generated tests: error occurred '${e.message}'", + title = "Failed to save Sarif report" + ) } try { @@ -280,7 +285,11 @@ object TestGenerator { } } } catch (e: Exception) { - logger.error { "Cannot save tests generation report: error occurred '${e.message}'" } + showErrorDialogLater( + project, + message = "Cannot save tests generation report: error occurred '${e.message}'", + title = "Failed to save tests report" + ) } } @@ -393,6 +402,10 @@ object TestGenerator { } private fun showCreatingClassError(project: Project, testClassName: String) { - logger.error { "Cannot Create Class '$testClassName'" } + showErrorDialogLater( + project, + message = "Cannot Create Class '$testClassName'", + title = "Failed to Create Class" + ) } } diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/UtTestsDialogProcessor.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/UtTestsDialogProcessor.kt index 128b435242..6e23545a9c 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/UtTestsDialogProcessor.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/UtTestsDialogProcessor.kt @@ -40,6 +40,7 @@ import java.nio.file.Paths import java.util.concurrent.TimeUnit import mu.KotlinLogging import org.jetbrains.kotlin.idea.util.module +import org.utbot.intellij.plugin.error.showErrorDialogLater object UtTestsDialogProcessor { @@ -165,7 +166,11 @@ object UtTestsDialogProcessor { } if (notEmptyCases.isEmpty()) { - logger.error { "Failed to generate unit tests for class $className" } + showErrorDialogLater( + model.project, + errorMessage(className, secondsTimeout), + title = "Failed to generate unit tests for class $className" + ) } else { testCasesByClass[srcClass] = notEmptyCases }