Skip to content

Commit

Permalink
Throw an error for any item that resolves as undefined (#825)
Browse files Browse the repository at this point in the history
* Throw an error for any item that resolves as undefined

* Add output log

* Remove output log append due to it being in the API

* Revert main from the webpack

* outputChannel appendLog

* Add the prod task (I think this is why the build fails)

* Need webpack-prod so webpack bundle will be present

* Shorten message for anything displayed on the tree UX
  • Loading branch information
nturinski authored Mar 6, 2024
1 parent 12ec0ee commit 5542cc4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@
]
},
"scripts": {
"vscode:prepublish": "npm run cleanReadme",
"build": "tsc && gulp webpack-prod",
"vscode:prepublish": "npm run webpack-prod",
"build": "tsc",
"cleanReadme": "gulp cleanReadme",
"compile": "tsc -watch",
"package": "vsce package --githubBranch main",
Expand All @@ -581,6 +581,7 @@
"pretest": "gulp preTest",
"test": "node ./out/test/runTest.js",
"webpack": "tsc && gulp webpack-dev",
"webpack-prod": "npm run build && gulp webpack-prod",
"webpack-profile": "webpack --profile --json --mode production > webpack-stats.json && echo Use http://webpack.github.io/analyse to analyze the stats",
"all": "npm i && npm run lint && npm test",
"api-extractor": "tsc -p ./api && api-extractor run -c ./api/api-extractor.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import { AzExtTreeItem, createSubscriptionContext, ISubscriptionContext } from '@microsoft/vscode-azext-utils';
import type { AppResource, AppResourceResolver } from '@microsoft/vscode-azext-utils/hostapi';
import { l10n } from 'vscode';
import type { AzureResource, ResourceModelBase } from '../../../../api/src/index';
import { ext } from '../../../extensionVariables';
import { CompatibleBranchDataProviderBase } from '../CompatibleBranchDataProviderBase';
import { CompatibleResolvedApplicationResourceTreeItem } from './CompatibleApplicationResourceTreeItem';

Expand All @@ -26,9 +28,12 @@ export class CompatibleApplicationResourceBranchDataProvider<TResource extends A
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(element.subscription);

const resolved = await this.resolver.resolveResource(subscriptionContext, oldAppResource);
// the fact that resolved can be null makes this painful to assert with nonNullValue
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const result = CompatibleResolvedApplicationResourceTreeItem.Create(element, resolved!, subscriptionContext, this, element) as unknown as TModel;
if (!resolved) {
const noResolveError = l10n.t('Could not resolve resource "{0}"', element.id);
ext.outputChannel.appendLog(noResolveError);
throw new Error(noResolveError);
}
const result = CompatibleResolvedApplicationResourceTreeItem.Create(element, resolved, subscriptionContext, this, element) as unknown as TModel;
Object.defineProperty(result, 'fullId', {
get: () => {
return element.id;
Expand Down
7 changes: 5 additions & 2 deletions src/utils/wrapFunctionsInTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ function stringifyError(e: unknown): string {
function handleError(e: unknown, functionName: string): never {
ext.outputChannel.appendLog(`Internal error: '${functionName}' threw an exception\n\t${stringifyError(e)}`);
if (e instanceof Error) {
// shortened message since it might be displayed on the tree
e.message = `Internal error: '${functionName}' threw exception ${parseError(e).message}`;
e.message = functionName === 'branchDataProvider.getResourceItem' ?
// shortened message for anything displayed on the tree
parseError(e).message :
`Internal error: '${functionName}' threw exception ${parseError(e).message}`;
}

throw e;
}

Expand Down

0 comments on commit 5542cc4

Please sign in to comment.