Skip to content

Commit 23df367

Browse files
Fix create function app when workspace items are selected (#3732)
1 parent 7ef7486 commit 23df367

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/commands/createFunctionApp/createFunctionApp.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import { SlotTreeItem } from '../../tree/SlotTreeItem';
1010
import { ICreateFunctionAppContext, SubscriptionTreeItem } from '../../tree/SubscriptionTreeItem';
1111
import { ISiteCreatedOptions } from './showSiteCreated';
1212

13+
function isSubscription(item?: AzExtParentTreeItem): boolean {
14+
try {
15+
// Accessing item.subscription throws an error for some workspace items
16+
// see https://github.com/microsoft/vscode-azurefunctions/issues/3731
17+
return !!item && !!item.subscription;
18+
} catch {
19+
return false;
20+
}
21+
}
22+
1323
export async function createFunctionApp(context: IActionContext & Partial<ICreateFunctionAppContext>, subscription?: AzExtParentTreeItem | string, nodesOrNewResourceGroupName?: string | (string | AzExtParentTreeItem)[]): Promise<string> {
1424
const newResourceGroupName = Array.isArray(nodesOrNewResourceGroupName) ? undefined : nodesOrNewResourceGroupName;
1525
let node: AzExtParentTreeItem | undefined;
@@ -18,7 +28,7 @@ export async function createFunctionApp(context: IActionContext & Partial<ICreat
1828
if (!node) {
1929
throw new Error(localize('noMatchingSubscription', 'Failed to find a subscription matching id "{0}".', subscription));
2030
}
21-
} else if (!subscription) {
31+
} else if (!isSubscription(subscription)) {
2232
node = await ext.rgApi.appResourceTree.showTreeItemPicker<AzExtParentTreeItem>(SubscriptionTreeItem.contextValue, context);
2333
} else {
2434
node = subscription;

0 commit comments

Comments
 (0)