Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
try {
var results: List<ProcessedSarifResult> = emptyList()

withTempFile { tempFile, tempFilePath ->
withTempFile { _, tempFilePath ->

val command = buildString {
append(cliCommand)
Expand All @@ -437,9 +437,20 @@
}
}

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

Check warning on line 450 in src/main/kotlin/com/codacy/intellij/plugin/services/cli/CodacyCli.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/kotlin/com/codacy/intellij/plugin/services/cli/CodacyCli.kt#L450

Expression with labels increase complexity and affect maintainability.
}

results = fileOutput
results = fileOutput.getOrNull()
.let { SarifUtil.readReport(StringReader(it)).runs }
?.let(::processSarifResults)
?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,7 +56,6 @@ class Config : PersistentStateComponent<Config.State> {

override fun loadState(state: State) {
this.state = state
this.apiToken = loadApiToken()
log.info("Configuration loaded")
}

Expand All @@ -64,9 +64,14 @@ class Config : PersistentStateComponent<Config.State> {
}

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)
Expand Down