diff --git a/package.json b/package.json index 01da4bacd..2331a8dcc 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/snyk/common/constants/commands.ts b/src/snyk/common/constants/commands.ts index ed4d71000..527296e6c 100644 --- a/src/snyk/common/constants/commands.ts +++ b/src/snyk/common/constants/commands.ts @@ -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'; diff --git a/src/snyk/common/constants/views.ts b/src/snyk/common/constants/views.ts index 44b362e86..438827751 100644 --- a/src/snyk/common/constants/views.ts +++ b/src/snyk/common/constants/views.ts @@ -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', diff --git a/src/snyk/common/error/errorHandler.ts b/src/snyk/common/error/errorHandler.ts index 835abb015..24f568a97 100644 --- a/src/snyk/common/error/errorHandler.ts +++ b/src/snyk/common/error/errorHandler.ts @@ -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'; @@ -17,7 +17,7 @@ export class ErrorHandler { contextService: IContextService, loadingBadge: ILoadingBadge, ): Promise { - await contextService.setContext(SNYK_CONTEXT.ERROR, SNYK_ERROR_CODES.BLOCKING); + await contextService.setContext(SNYK_CONTEXT.ERROR, error); loadingBadge.setLoadingBadge(true); ErrorHandler.handle(error, logger); } diff --git a/src/snyk/common/services/productService.ts b/src/snyk/common/services/productService.ts index 2921de123..96e02559d 100644 --- a/src/snyk/common/services/productService.ts +++ b/src/snyk/common/services/productService.ts @@ -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'; diff --git a/src/snyk/extension.ts b/src/snyk/extension.ts index 61e2022cd..f603a4a88 100644 --- a/src/snyk/extension.ts +++ b/src/snyk/extension.ts @@ -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'; @@ -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, @@ -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 { @@ -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, @@ -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; @@ -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); + }), ); } } diff --git a/src/snyk/snykCode/views/webviewPanelSerializer.ts b/src/snyk/snykCode/views/webviewPanelSerializer.ts index e48327bef..fca27e31a 100644 --- a/src/snyk/snykCode/views/webviewPanelSerializer.ts +++ b/src/snyk/snykCode/views/webviewPanelSerializer.ts @@ -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, State> implements vscode.WebviewPanelSerializer diff --git a/src/snyk/snykOss/ossService.ts b/src/snyk/snykOss/ossService.ts index 235cb0e9d..271fd3449 100644 --- a/src/snyk/snykOss/ossService.ts +++ b/src/snyk/snykOss/ossService.ts @@ -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'; diff --git a/src/test/unit/common/commands/commandController.test.ts b/src/test/unit/common/commands/commandController.test.ts index 7cc3226a4..3da22aa27 100644 --- a/src/test/unit/common/commands/commandController.test.ts +++ b/src/test/unit/common/commands/commandController.test.ts @@ -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';