Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error for any item that resolves as undefined #825

Merged
merged 8 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentionally included?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the npm run build shouldn't run webpack. It wasn't actually changing the line return await extension.activate(ctx, perfStats, true); either (where the true is ignoreBundle) so it wasn't actually prepping it to be used with webpack.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that this matches our other extensions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should stop using Gulp and match the Docker extension's build scripts and such...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agreed: #826

"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
Loading