From 2eb49f523dcd920c9c969ba81a81af817894a7b3 Mon Sep 17 00:00:00 2001 From: Markus Frey Date: Wed, 19 Jul 2023 18:38:31 +0200 Subject: [PATCH] Throw a verbose error if the function project root can't be found on deploy (#3764) Inform the user that the project root could not be found instead of throwing a generic null value error and suggest a possible cause. --- src/commands/deploy/deploy.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/commands/deploy/deploy.ts b/src/commands/deploy/deploy.ts index cf7b3e4d2..0039fe9d6 100644 --- a/src/commands/deploy/deploy.ts +++ b/src/commands/deploy/deploy.ts @@ -5,9 +5,9 @@ import type { SiteConfigResource } from '@azure/arm-appservice'; import { IDeployContext, IDeployPaths, getDeployFsPath, getDeployNode, deploy as innerDeploy, showDeployConfirmation } from '@microsoft/vscode-azext-azureappservice'; -import { DialogResponses, IActionContext, nonNullValue } from '@microsoft/vscode-azext-utils'; +import { DialogResponses, IActionContext } from '@microsoft/vscode-azext-utils'; import * as vscode from 'vscode'; -import { CodeAction, ConnectionType, DurableBackend, DurableBackendValues, ProjectLanguage, ScmType, deploySubpathSetting, functionFilter, remoteBuildSetting } from '../../constants'; +import { CodeAction, ConnectionType, DurableBackend, DurableBackendValues, ProjectLanguage, ScmType, deploySubpathSetting, functionFilter, hostFileName, remoteBuildSetting } from '../../constants'; import { ext } from '../../extensionVariables'; import { addLocalFuncTelemetry } from '../../funcCoreTools/getLocalFuncCoreToolsVersion'; import { localize } from '../../localize'; @@ -45,7 +45,12 @@ async function deploy(actionContext: IActionContext, arg1: vscode.Uri | string | addLocalFuncTelemetry(actionContext, deployPaths.workspaceFolder.uri.fsPath); - const projectPath: string = nonNullValue(await tryGetFunctionProjectRoot(actionContext, deployPaths.workspaceFolder)); + const projectPath: string | undefined = await tryGetFunctionProjectRoot(actionContext, deployPaths.workspaceFolder); + if (projectPath === undefined) { + const message: string = localize('functionProjectRootNotFound', 'No azure function project root could be found. This can be caused by a missing {0} file.', hostFileName); + throw new Error(message); + } + const context: IFuncDeployContext = Object.assign(actionContext, deployPaths, { action: CodeAction.Deploy, defaultAppSetting: 'defaultFunctionAppToDeploy', projectPath }); if (treeUtils.isAzExtTreeItem(arg1)) { if (!arg1.contextValue.match(ResolvedFunctionAppResource.pickSlotContextValue) &&