diff --git a/src/commands/createFunctionApp/createFunctionApp.ts b/src/commands/createFunctionApp/createFunctionApp.ts index 0bec225c6..4df53aa58 100644 --- a/src/commands/createFunctionApp/createFunctionApp.ts +++ b/src/commands/createFunctionApp/createFunctionApp.ts @@ -10,6 +10,16 @@ import { SlotTreeItem } from '../../tree/SlotTreeItem'; import { ICreateFunctionAppContext, SubscriptionTreeItem } from '../../tree/SubscriptionTreeItem'; import { ISiteCreatedOptions } from './showSiteCreated'; +function isSubscription(item?: AzExtParentTreeItem): boolean { + try { + // Accessing item.subscription throws an error for some workspace items + // see https://github.com/microsoft/vscode-azurefunctions/issues/3731 + return !!item && !!item.subscription; + } catch { + return false; + } +} + export async function createFunctionApp(context: IActionContext & Partial, subscription?: AzExtParentTreeItem | string, nodesOrNewResourceGroupName?: string | (string | AzExtParentTreeItem)[]): Promise { const newResourceGroupName = Array.isArray(nodesOrNewResourceGroupName) ? undefined : nodesOrNewResourceGroupName; let node: AzExtParentTreeItem | undefined; @@ -18,7 +28,7 @@ export async function createFunctionApp(context: IActionContext & Partial(SubscriptionTreeItem.contextValue, context); } else { node = subscription;