Skip to content

Commit

Permalink
Fix create function app when workspace items are selected (#3732)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweininger authored Jun 28, 2023
1 parent 7ef7486 commit 23df367
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/commands/createFunctionApp/createFunctionApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICreateFunctionAppContext>, subscription?: AzExtParentTreeItem | string, nodesOrNewResourceGroupName?: string | (string | AzExtParentTreeItem)[]): Promise<string> {
const newResourceGroupName = Array.isArray(nodesOrNewResourceGroupName) ? undefined : nodesOrNewResourceGroupName;
let node: AzExtParentTreeItem | undefined;
Expand All @@ -18,7 +28,7 @@ export async function createFunctionApp(context: IActionContext & Partial<ICreat
if (!node) {
throw new Error(localize('noMatchingSubscription', 'Failed to find a subscription matching id "{0}".', subscription));
}
} else if (!subscription) {
} else if (!isSubscription(subscription)) {
node = await ext.rgApi.appResourceTree.showTreeItemPicker<AzExtParentTreeItem>(SubscriptionTreeItem.contextValue, context);
} else {
node = subscription;
Expand Down

0 comments on commit 23df367

Please sign in to comment.