Skip to content

Commit

Permalink
Merge pull request #936 from JetBrains/rival/fix-RIDER-113475
Browse files Browse the repository at this point in the history
 Show a more accurate description of errors if the deployment fails
  • Loading branch information
rafaelldi authored Oct 9, 2024
2 parents 7ca40a7 + 4bd30a4 commit d23aed5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions PluginsAndFeatures/azure-toolkit-for-rider/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixed

- Allow comments in the local.settings.json file ([#900](https://github.com/JetBrains/azure-tools-for-intellij/issues/900))
- Show a more accurate description of errors if the deployment fails ([RIDER-113475](https://youtrack.jetbrains.com/issue/RIDER-113475))

## [4.2.1] - 2024-10-04

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
* Copyright 2018-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

@file:Suppress("DuplicatedCode")

package com.microsoft.azure.toolkit.intellij.appservice

import com.azure.core.exception.HttpResponseException
import com.intellij.execution.ExecutionException
import com.intellij.ide.BrowserUtil
import com.intellij.notification.Notification
import com.intellij.notification.NotificationAction
import com.intellij.notification.NotificationType
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
Expand Down Expand Up @@ -38,6 +45,8 @@ class DotNetAppServiceDeployer(private val project: Project) {
): Result<Unit> {
target.status = AzResource.Status.DEPLOYING

checkIfTargetIsValid(target)

val publishProjectResult = ArtifactService
.getInstance(project)
.publishProjectToFolder(
Expand Down Expand Up @@ -72,6 +81,8 @@ class DotNetAppServiceDeployer(private val project: Project) {
): Result<Unit> {
target.status = AzResource.Status.DEPLOYING

checkIfTargetIsValid(target)

val publishProjectResult = ArtifactService
.getInstance(project)
.publishProjectToFolder(
Expand All @@ -97,6 +108,24 @@ class DotNetAppServiceDeployer(private val project: Project) {
)
}

private fun checkIfTargetIsValid(target: AppServiceAppBase<*, *, *>) {
val appSettings = target.appSettings

val websiteRunFromPackage = appSettings?.get("WEBSITE_RUN_FROM_PACKAGE")
if (websiteRunFromPackage != null && websiteRunFromPackage.startsWith("http")) {
Notification(
"Azure AppServices",
"Invalid application settings",
"The WEBSITE_RUN_FROM_PACKAGE environment variable is set to an URL in the application settings. This can prevent successful deployment.",
NotificationType.WARNING
)
.addAction(NotificationAction.createSimple("Open application on the Portal") {
BrowserUtil.open(target.portalUrl)
})
.notify(project)
}
}

private fun packageWebAppArtifactDirectory(artifactFolder: File): File? {
try {
val zipFile = Files.createTempFile(artifactFolder.nameWithoutExtension, ".zip").toFile()
Expand Down Expand Up @@ -134,7 +163,15 @@ class DotNetAppServiceDeployer(private val project: Project) {
updateStatusText("Starting deployment...")
updateStatusText("Trying to deploy artifact to ${webAppBase.name()}...")

webAppBase.zipDeployAsync(zipFile)?.awaitSingleOrNull()
try {
webAppBase.zipDeployAsync(zipFile)?.awaitSingleOrNull()
} catch (e: HttpResponseException) {
LOG.warn("Unable to deploy artifact to Azure resource due to the unsuccessful status code", e)
return Result.failure(ExecutionException(e.message))
} catch (e: Exception) {
LOG.warn("Unable to deploy artifact to Azure resource", e)
return Result.failure(ExecutionException(e.message))
}

updateStatusText("Successfully deployed the artifact to ${webAppBase.defaultHostname()}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ abstract class AzureDeploymentState<T>(
processHandler.startNotify()
consoleView.attachToProcess(processHandler)

val processScope = scope.childScope("Azure Deployment scope")
processScope.launch(Dispatchers.Default) {
val job = scope.launch(Dispatchers.Default) {
try {
val result = executeSteps(processHandler)
processHandler.putUserData(RunConfigurationUtils.AZURE_RUN_STATE_RESULT, true)
Expand All @@ -49,18 +48,16 @@ abstract class AzureDeploymentState<T>(
catch (ce: CancellationException) {
processHandlerMessenger?.info("Process was cancelled")
onFail(ce, processHandler)
throw ce
}
catch (t: Throwable) {
processHandlerMessenger?.error(t)
onFail(t, processHandler)
throw t
}
}

processHandler.addProcessListener(object : ProcessAdapter() {
override fun processTerminated(event: ProcessEvent) {
processScope.cancel()
job.cancel()
}
})

Expand Down

0 comments on commit d23aed5

Please sign in to comment.