diff --git a/PluginsAndFeatures/azure-toolkit-for-rider/CHANGELOG.md b/PluginsAndFeatures/azure-toolkit-for-rider/CHANGELOG.md index 7af0f6ff17..5acc3bd787 100644 --- a/PluginsAndFeatures/azure-toolkit-for-rider/CHANGELOG.md +++ b/PluginsAndFeatures/azure-toolkit-for-rider/CHANGELOG.md @@ -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 diff --git a/PluginsAndFeatures/azure-toolkit-for-rider/azure-intellij-plugin-appservice-dotnet/src/main/kotlin/com/microsoft/azure/toolkit/intellij/appservice/DotNetAppServiceDeployer.kt b/PluginsAndFeatures/azure-toolkit-for-rider/azure-intellij-plugin-appservice-dotnet/src/main/kotlin/com/microsoft/azure/toolkit/intellij/appservice/DotNetAppServiceDeployer.kt index a2a5ad3a6d..04c012e4e9 100644 --- a/PluginsAndFeatures/azure-toolkit-for-rider/azure-intellij-plugin-appservice-dotnet/src/main/kotlin/com/microsoft/azure/toolkit/intellij/appservice/DotNetAppServiceDeployer.kt +++ b/PluginsAndFeatures/azure-toolkit-for-rider/azure-intellij-plugin-appservice-dotnet/src/main/kotlin/com/microsoft/azure/toolkit/intellij/appservice/DotNetAppServiceDeployer.kt @@ -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 @@ -38,6 +45,8 @@ class DotNetAppServiceDeployer(private val project: Project) { ): Result { target.status = AzResource.Status.DEPLOYING + checkIfTargetIsValid(target) + val publishProjectResult = ArtifactService .getInstance(project) .publishProjectToFolder( @@ -72,6 +81,8 @@ class DotNetAppServiceDeployer(private val project: Project) { ): Result { target.status = AzResource.Status.DEPLOYING + checkIfTargetIsValid(target) + val publishProjectResult = ArtifactService .getInstance(project) .publishProjectToFolder( @@ -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() @@ -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()}") diff --git a/PluginsAndFeatures/azure-toolkit-for-rider/azure-intellij-plugin-lib-dotnet/src/main/kotlin/com/microsoft/azure/toolkit/intellij/legacy/common/AzureDeploymentState.kt b/PluginsAndFeatures/azure-toolkit-for-rider/azure-intellij-plugin-lib-dotnet/src/main/kotlin/com/microsoft/azure/toolkit/intellij/legacy/common/AzureDeploymentState.kt index dfa9f615d5..0fa55063be 100644 --- a/PluginsAndFeatures/azure-toolkit-for-rider/azure-intellij-plugin-lib-dotnet/src/main/kotlin/com/microsoft/azure/toolkit/intellij/legacy/common/AzureDeploymentState.kt +++ b/PluginsAndFeatures/azure-toolkit-for-rider/azure-intellij-plugin-lib-dotnet/src/main/kotlin/com/microsoft/azure/toolkit/intellij/legacy/common/AzureDeploymentState.kt @@ -39,8 +39,7 @@ abstract class AzureDeploymentState( 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) @@ -49,18 +48,16 @@ abstract class AzureDeploymentState( 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() } })