Skip to content

Commit

Permalink
SLI-1816 Interrupting the branch matching should not cause an error
Browse files Browse the repository at this point in the history
  • Loading branch information
eray-felek-sonarsource committed Jan 29, 2025
1 parent 5e24821 commit ae7b7ce
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import java.security.cert.X509Certificate
import java.util.UUID
import java.util.concurrent.CancellationException
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeoutException
import org.apache.commons.text.StringEscapeUtils
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError
Expand Down Expand Up @@ -160,6 +161,10 @@ import org.sonarsource.sonarlint.core.rpc.protocol.common.TokenDto
import org.sonarsource.sonarlint.core.rpc.protocol.common.UsernamePasswordDto


private const val INTERRUPTED_MESSAGE = "Interrupted while waiting for Sonar project branch matching result"

private const val TIMEOUT_MESSAGE = "Timeout while waiting for Sonar project branch matching result"

object SonarLintIntelliJClient : SonarLintRpcClientDelegate {

private const val SONAR_SCANNER_CONFIG_FILENAME = "sonar-project.properties"
Expand Down Expand Up @@ -644,11 +649,27 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate {
PerformInBackgroundOption.ALWAYS_BACKGROUND
) {
override fun run(indicator: ProgressIndicator) {
val result = repo.electBestMatchingServerBranchForCurrentHead(mainBranchName, allBranchesNames) ?: mainBranchName
resultFuture.complete(result)
try {
val result = repo.electBestMatchingServerBranchForCurrentHead(mainBranchName, allBranchesNames) ?: mainBranchName
resultFuture.complete(result)
} catch (e: InterruptedException) {
getService(project, SonarLintConsole::class.java).error(INTERRUPTED_MESSAGE, e)
} catch (e: TimeoutException) {
getService(project, SonarLintConsole::class.java).error(TIMEOUT_MESSAGE, e)
}
}
})
return computeOnPooledThread(project, "Waiting for branch matching result") { resultFuture.get() }
return computeOnPooledThread(project, "Waiting for branch matching result") {
try {
resultFuture.get()
} catch (e: InterruptedException) {
getService(project, SonarLintConsole::class.java).error(INTERRUPTED_MESSAGE, e)
null
} catch (e: TimeoutException) {
getService(project, SonarLintConsole::class.java).error(TIMEOUT_MESSAGE, e)
null
}
}
}

override fun matchProjectBranch(
Expand Down

0 comments on commit ae7b7ce

Please sign in to comment.