Skip to content

Commit

Permalink
chore: handle startup errors better [IDE-5] (#524)
Browse files Browse the repository at this point in the history
* refactor: remove generics from IDiagnosticsIssueProvider

* chore: optimize imports, remove warnings

* fix: add option to display errors during extension start up

* fix: linting issues

* revert: refactor of diagnostics provider
  • Loading branch information
bastiandoetsch authored Aug 30, 2024
1 parent 94d94f3 commit 12dde21
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@
"viewsWelcome": [
{
"view": "snyk.views.welcome",
"contents": "Snyk has encountered a problem. Please restart the extension: \n[Restart](command:snyk.start 'Restart Snyk')\nIf the error persists, please check your [settings](command:snyk.settings) and [contact us](https://snyk.io/contact-us/?utm_source=vsc)!",
"when": "snyk:error == 'blocking'"
"contents": "Snyk has encountered a problem. Please restart the extension: \n[Restart](command:snyk.start 'Restart Snyk')\nIf the error persists, please check your [settings](command:snyk.settings) and [contact us](https://snyk.io/contact-us/?utm_source=vsc).\n\n You can check the logs to see the exact error in [Snyk Security](command:snyk.showOutputChannel) and [Snyk Language Server](command:snyk.showLsOutputChannel) output channels.\n[Display Error](command:snyk.showErrorFromContext)\n",
"when": "snyk:error"
},
{
"view": "snyk.views.welcome",
Expand Down
1 change: 1 addition & 0 deletions src/snyk/common/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const SNYK_OPEN_ISSUE_COMMAND = 'snyk.showissue';
export const SNYK_IGNORE_ISSUE_COMMAND = 'snyk.ignoreissue';
export const SNYK_SHOW_OUTPUT_COMMAND = 'snyk.showOutputChannel';
export const SNYK_SHOW_LS_OUTPUT_COMMAND = 'snyk.showLsOutputChannel';
export const SNYK_SHOW_ERROR_FROM_CONTEXT_COMMAND = 'snyk.showErrorFromContext';
export const SNYK_GET_LESSON_COMMAND = 'snyk.getLearnLesson';
export const SNYK_GET_SETTINGS_SAST_ENABLED = 'snyk.getSettingsSastEnabled';
export const SNYK_SET_BASE_BRANCH_COMMAND = 'snyk.setBaseBranch';
Expand Down
4 changes: 0 additions & 4 deletions src/snyk/common/constants/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export const SNYK_CONTEXT = {
DELTA_FINDINGS_ENABLED: 'deltaFindingsEnabled',
};

export const SNYK_ERROR_CODES = {
BLOCKING: 'blocking',
};

export const SNYK_ANALYSIS_STATUS = {
FILTERS: 'Supported extentions',
COLLECTING: 'Collecting files',
Expand Down
4 changes: 2 additions & 2 deletions src/snyk/common/error/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ILoadingBadge } from '../../base/views/loadingBadge';
import { SNYK_CONTEXT, SNYK_ERROR_CODES } from '../constants/views';
import { SNYK_CONTEXT } from '../constants/views';
import { ILog } from '../logger/interfaces';
import { IContextService } from '../services/contextService';
import { ErrorReporter, Tags } from './errorReporter';
Expand All @@ -17,7 +17,7 @@ export class ErrorHandler {
contextService: IContextService,
loadingBadge: ILoadingBadge,
): Promise<void> {
await contextService.setContext(SNYK_CONTEXT.ERROR, SNYK_ERROR_CODES.BLOCKING);
await contextService.setContext(SNYK_CONTEXT.ERROR, error);
loadingBadge.setLoadingBadge(true);
ErrorHandler.handle(error, logger);
}
Expand Down
2 changes: 1 addition & 1 deletion src/snyk/common/services/productService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CodeActionsProvider } from '../editor/codeActionsProvider';
import { ILanguageServer } from '../languageServer/languageServer';
import { Issue, Scan, ScanProduct, ScanStatus } from '../languageServer/types';
import { ILog } from '../logger/interfaces';
import { IViewManagerService } from '../services/viewManagerService';
import { IViewManagerService } from './viewManagerService';
import { IProductWebviewProvider } from '../views/webviewProvider';
import { ExtensionContext } from '../vscode/extensionContext';
import { IVSCodeLanguages } from '../vscode/languages';
Expand Down
14 changes: 9 additions & 5 deletions src/snyk/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { AuthenticationService } from './base/services/authenticationService';
import { ScanModeService } from './base/services/scanModeService';
import { EmptyTreeDataProvider } from './base/views/emptyTreeDataProvider';
import { SupportProvider } from './base/views/supportProvider';
import { messages } from './cli/messages/messages';
import { CommandController } from './common/commands/commandController';
import { OpenIssueCommandArg } from './common/commands/types';
import { configuration } from './common/configuration/instance';
Expand All @@ -21,6 +20,7 @@ import {
SNYK_SET_BASE_BRANCH_COMMAND,
SNYK_SET_TOKEN_COMMAND,
SNYK_SETTINGS_COMMAND,
SNYK_SHOW_ERROR_FROM_CONTEXT_COMMAND,
SNYK_SHOW_LS_OUTPUT_COMMAND,
SNYK_SHOW_OUTPUT_COMMAND,
SNYK_START_COMMAND,
Expand Down Expand Up @@ -77,7 +77,7 @@ import OssIssueTreeProvider from './snykOss/providers/ossVulnerabilityTreeProvid
import { OssVulnerabilityCountService } from './snykOss/services/vulnerabilityCount/ossVulnerabilityCountService';
import { FeatureFlagService } from './common/services/featureFlagService';
import { DiagnosticsIssueProvider } from './common/services/diagnosticsService';
import { CodeIssueData, IacIssueData, OssIssueData, ScanProduct } from './common/languageServer/types';
import { CodeIssueData, IacIssueData, OssIssueData } from './common/languageServer/types';

class SnykExtension extends SnykLib implements IExtension {
public async activate(vscodeContext: vscode.ExtensionContext): Promise<void> {
Expand Down Expand Up @@ -270,8 +270,8 @@ class SnykExtension extends SnykLib implements IExtension {
this.folderConfigs,
);

let securityCodeView = SNYK_VIEW_ANALYSIS_CODE_SECURITY;
let codeQualityView = SNYK_VIEW_ANALYSIS_CODE_QUALITY;
const securityCodeView = SNYK_VIEW_ANALYSIS_CODE_SECURITY;
const codeQualityView = SNYK_VIEW_ANALYSIS_CODE_QUALITY;

const codeSecurityTree = vscode.window.createTreeView(securityCodeView, {
treeDataProvider: codeSecurityIssueProvider,
Expand Down Expand Up @@ -409,7 +409,7 @@ class SnykExtension extends SnykLib implements IExtension {

private initDependencyDownload(): DownloadService {
this.downloadService.downloadOrUpdate().catch(err => {
Logger.error(`${messages.lsDownloadFailed} ${ErrorHandler.stringifyError(err)}`);
void ErrorHandler.handleGlobal(err, Logger, this.contextService, this.loadingBadge);
});

return this.downloadService;
Expand Down Expand Up @@ -444,6 +444,10 @@ class SnykExtension extends SnykLib implements IExtension {
vscode.commands.registerCommand(SNYK_SET_BASE_BRANCH_COMMAND, (folderPath: string) =>
this.commandController.setBaseBranch(folderPath),
),
vscode.commands.registerCommand(SNYK_SHOW_ERROR_FROM_CONTEXT_COMMAND, () => {
const err = this.contextService.viewContext[SNYK_CONTEXT.ERROR] as Error;
void vscode.window.showErrorMessage(err.message);
}),
);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/snyk/snykCode/views/webviewPanelSerializer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as vscode from 'vscode';
import { WebviewProvider } from '../../../snyk/common/views/webviewProvider';
import { Logger } from '../../common/logger/logger';

export class WebviewPanelSerializer<Provider extends WebviewProvider<State>, State>
implements vscode.WebviewPanelSerializer
Expand Down
2 changes: 1 addition & 1 deletion src/snyk/snykOss/ossService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Subscription } from 'rxjs';
import { IConfiguration } from '../common/configuration/configuration';
import { IWorkspaceTrust } from '../common/configuration/trustedFolders';
import { ILanguageServer } from '../common/languageServer/languageServer';
import { CodeIssueData, OssIssueData, Scan, ScanProduct } from '../common/languageServer/types';
import { OssIssueData, Scan, ScanProduct } from '../common/languageServer/types';
import { ILog } from '../common/logger/interfaces';
import { ProductService } from '../common/services/productService';
import { IViewManagerService } from '../common/services/viewManagerService';
Expand Down
1 change: 0 additions & 1 deletion src/test/unit/common/commands/commandController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as util from 'util';
import { IAuthenticationService } from '../../../../snyk/base/services/authenticationService';
import { ScanModeService } from '../../../../snyk/base/services/scanModeService';
import { CommandController } from '../../../../snyk/common/commands/commandController';
import { COMMAND_DEBOUNCE_INTERVAL } from '../../../../snyk/common/constants/general';
import { CodeIssueData, IacIssueData } from '../../../../snyk/common/languageServer/types';
import { IOpenerService } from '../../../../snyk/common/services/openerService';
import { IProductService } from '../../../../snyk/common/services/productService';
Expand Down

0 comments on commit 12dde21

Please sign in to comment.