Skip to content

Commit cc83e93

Browse files
authored
Fix bug for icon changing and undefined kind (#4571)
1 parent 8ad712b commit cc83e93

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/FunctionAppResolver.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type ResourceGraphClient } from "@azure/arm-resourcegraph";
22
import { createWebSiteClient } from "@microsoft/vscode-azext-azureappservice";
3-
import { callWithTelemetryAndErrorHandling, nonNullProp, nonNullValueAndProp, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
3+
import { getResourceGroupFromId } from "@microsoft/vscode-azext-azureutils";
4+
import { callWithTelemetryAndErrorHandling, nonNullProp, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
45
import { type AppResource, type AppResourceResolver } from "@microsoft/vscode-azext-utils/hostapi";
56
import { ResolvedFunctionAppResource } from "./tree/ResolvedFunctionAppResource";
67
import { ResolvedContainerizedFunctionAppResource } from "./tree/containerizedFunctionApp/ResolvedContainerizedFunctionAppResource";
@@ -91,13 +92,16 @@ export class FunctionAppResolver implements AppResourceResolver {
9192
}
9293

9394
const siteModel = this.siteCache.get(nonNullProp(resource, 'id').toLowerCase());
94-
if (nonNullValueAndProp(siteModel, 'kind') === 'functionapp,linux,container,azurecontainerapps') {
95-
// need the full site to resolve containerized function apps
95+
if (!siteModel || siteModel.kind === 'functionapp,linux,container,azurecontainerapps') {
96+
// if the site model is not found or if it's a containerized function app, we need the full site details
9697
const client = await createWebSiteClient({ ...context, ...subContext });
97-
const fullSite = await client.webApps.get(nonNullValueAndProp(siteModel, 'resourceGroup'), nonNullValueAndProp(siteModel, 'name'));
98-
return ResolvedContainerizedFunctionAppResource.createResolvedFunctionAppResource(context, subContext, fullSite);
99-
}
100-
if (siteModel) {
98+
const fullSite = await client.webApps.get(getResourceGroupFromId(resource.id), resource.name);
99+
if (fullSite.kind === 'functionapp,linux,container,azurecontainerapps') {
100+
return ResolvedContainerizedFunctionAppResource.createResolvedFunctionAppResource(context, subContext, fullSite);
101+
}
102+
103+
return new ResolvedFunctionAppResource(subContext, fullSite);
104+
} else if (siteModel) {
101105
return new ResolvedFunctionAppResource(subContext, undefined, siteModel);
102106
}
103107

src/tree/ResolvedFunctionAppResource.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { type Site, type SiteConfig, type SiteSourceControl, type StringDictionary } from "@azure/arm-appservice";
77
import { DeleteLastServicePlanStep, DeleteSiteStep, DeploymentTreeItem, DeploymentsTreeItem, LogFilesTreeItem, ParsedSite, SiteFilesTreeItem, createWebSiteClient, getFile, type IDeleteSiteWizardContext } from "@microsoft/vscode-azext-azureappservice";
88
import { AppSettingTreeItem, AppSettingsTreeItem } from "@microsoft/vscode-azext-azureappsettings";
9-
import { AzureWizard, DeleteConfirmationStep, callWithTelemetryAndErrorHandling, nonNullValue, type AzExtTreeItem, type IActionContext, type ISubscriptionContext, type TreeItemIconPath } from "@microsoft/vscode-azext-utils";
9+
import { AzureWizard, DeleteConfirmationStep, callWithTelemetryAndErrorHandling, type AzExtTreeItem, type IActionContext, type ISubscriptionContext, type TreeItemIconPath } from "@microsoft/vscode-azext-utils";
1010
import { type ResolvedAppResourceBase } from "@microsoft/vscode-azext-utils/hostapi";
1111
import { latestGAVersion, tryParseFuncVersion, type FuncVersion } from "../FuncVersion";
1212
import { type FunctionAppModel } from "../FunctionAppResolver";
@@ -93,7 +93,6 @@ export class ResolvedFunctionAppResource extends ResolvedFunctionAppBase impleme
9393
const webClient = await createWebSiteClient({ ...context, ...this._subscription });
9494
const rawSite = await webClient.webApps.get(this.dataModel.resourceGroup, this.dataModel.name);
9595
this._site = new ParsedSite(rawSite, this._subscription);
96-
this.data = rawSite;
9796
this.addValuesToMask(this._site);
9897
}
9998
}
@@ -104,7 +103,6 @@ export class ResolvedFunctionAppResource extends ResolvedFunctionAppBase impleme
104103
// try to lazy load the site if it hasn't been initialized yet
105104
void this.initSite(context);
106105
});
107-
// If the site is not initialized, we should throw an error
108106
throw new Error(localize('siteNotSet', 'Site is not initialized. Please try again in a moment.'));
109107
}
110108
return this._site;
@@ -176,8 +174,11 @@ export class ResolvedFunctionAppResource extends ResolvedFunctionAppBase impleme
176174

177175
// on refresh, we should reinitialize the site to ensure we have the latest data
178176
const client = await this.site.createClient(context);
179-
this._site = new ParsedSite(nonNullValue(await client.getSite(), 'site'), this._subscription);
180-
this.dataModel = this.createDataModelFromSite(this._site.rawSite);
177+
const site = await client.getSite();
178+
if (site) {
179+
this.dataModel = this.createDataModelFromSite(site);
180+
this._site = new ParsedSite(site, this._subscription);
181+
}
181182
}
182183

183184
public async getVersion(context: IActionContext): Promise<FuncVersion> {

0 commit comments

Comments
 (0)