diff --git a/src/main/kotlin/com/codacy/intellij/plugin/services/cli/CodacyCli.kt b/src/main/kotlin/com/codacy/intellij/plugin/services/cli/CodacyCli.kt index b374d3f..fe12bf6 100644 --- a/src/main/kotlin/com/codacy/intellij/plugin/services/cli/CodacyCli.kt +++ b/src/main/kotlin/com/codacy/intellij/plugin/services/cli/CodacyCli.kt @@ -411,7 +411,7 @@ class CodacyCli() { try { var results: List = emptyList() - withTempFile { tempFile, tempFilePath -> + withTempFile { _, tempFilePath -> val command = buildString { append(cliCommand) @@ -437,9 +437,20 @@ class CodacyCli() { } } - val fileOutput = File(tempFilePath.toUri()).readText() + val fileOutput = runCatching { + File(tempFilePath.toUri()).readText() + } + + if (fileOutput.isFailure) { + notificationManager.createNotification( + "CLI tools has not generated a result file", + "Current document will not be analyzed, please try again", + NotificationType.ERROR + ).notify(project) + return@withTempFile + } - results = fileOutput + results = fileOutput.getOrNull() .let { SarifUtil.readReport(StringReader(it)).runs } ?.let(::processSarifResults) ?: emptyList() diff --git a/src/main/kotlin/com/codacy/intellij/plugin/services/common/Config.kt b/src/main/kotlin/com/codacy/intellij/plugin/services/common/Config.kt index 9f2ec36..39c5bdc 100644 --- a/src/main/kotlin/com/codacy/intellij/plugin/services/common/Config.kt +++ b/src/main/kotlin/com/codacy/intellij/plugin/services/common/Config.kt @@ -6,6 +6,7 @@ import com.intellij.credentialStore.CredentialAttributes import com.intellij.credentialStore.Credentials import com.intellij.ide.passwordSafe.PasswordSafe import com.intellij.openapi.components.* +import com.intellij.util.SlowOperations import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -55,7 +56,6 @@ class Config : PersistentStateComponent { override fun loadState(state: State) { this.state = state - this.apiToken = loadApiToken() log.info("Configuration loaded") } @@ -64,9 +64,14 @@ class Config : PersistentStateComponent { } private fun loadApiToken(): String? { - val credentialAttributes = createCredentialAttributes() - val credentials = PasswordSafe.instance.get(credentialAttributes) - return credentials?.getPasswordAsString() + val accessToken = SlowOperations.allowSlowOperations("Codacy: loadApiToken") + return try { + val credentialAttributes = createCredentialAttributes() + val credentials = PasswordSafe.instance.get(credentialAttributes) + credentials?.getPasswordAsString() + } finally { + accessToken.finish() + } } @OptIn(DelicateCoroutinesApi::class)