From d427e00ba3396e628dd49fc144c36565a029e854 Mon Sep 17 00:00:00 2001 From: Nagarjun Sanji Date: Mon, 23 Sep 2024 11:06:36 +0530 Subject: [PATCH] bug fix --- src/helpers/errorHandler.ts | 5 ++++- src/helpers/gitHelper.ts | 1 + src/helpers/index.ts | 2 +- src/test/helpers/errorHandler.test.ts | 9 +++++++-- tsconfig.json | 10 +--------- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/helpers/errorHandler.ts b/src/helpers/errorHandler.ts index 2dd31e4..967f225 100644 --- a/src/helpers/errorHandler.ts +++ b/src/helpers/errorHandler.ts @@ -1,17 +1,20 @@ import { Logger } from "./loggerHelper"; import { StatusBarMessageHelper } from "./statusBarMessageHelper"; +import { SentryHelper } from "./sentryHelper"; export class ErrorHandler { constructor( private statusBarMessageHelper: StatusBarMessageHelper, private logger: typeof Logger, + private sentryHelper: typeof SentryHelper, ) {} - public handleError(error: unknown) { + public handleError(error: any) { const errorMessage = this.extractErrorMessage(error); const errorStack = error instanceof Error ? error.stack : ""; this.logError(errorMessage, errorStack); this.showUserErrorMessage(errorMessage); + this.sentryHelper.captureException(new Error(`Error :`, error)); } private extractErrorMessage(error: unknown): string { diff --git a/src/helpers/gitHelper.ts b/src/helpers/gitHelper.ts index e1568a2..cf2d8c7 100644 --- a/src/helpers/gitHelper.ts +++ b/src/helpers/gitHelper.ts @@ -96,6 +96,7 @@ export class GitHelper { return await this.command.executeAsyncCommand(command); } catch (error: any) { Logger.logError(error); + this.sentryHelper.captureException(new Error(`Git Error : ${command}`, error)); return MessageStatus.UNKNOWN; } } diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 7088d75..6e7d29d 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -52,7 +52,7 @@ const debrickedDataHelper = new DebrickedDataHelper(); const globalStore = GlobalStore.getInstance(); const authHelper = new AuthHelper(showInputBoxHelper, statusBarMessageHelper, Logger, globalStore); -const errorHandler = new ErrorHandler(statusBarMessageHelper, Logger); +const errorHandler = new ErrorHandler(statusBarMessageHelper, Logger, SentryHelper); const commandHelper = new Command(authHelper, Logger); const commonHelper = new Common(Logger, showInputBoxHelper, globalStore); const gitHelper = new GitHelper( diff --git a/src/test/helpers/errorHandler.test.ts b/src/test/helpers/errorHandler.test.ts index 52033e3..69fed90 100644 --- a/src/test/helpers/errorHandler.test.ts +++ b/src/test/helpers/errorHandler.test.ts @@ -1,12 +1,14 @@ import { ErrorHandler } from "../../helpers/errorHandler"; -import { Logger } from "../../helpers"; +import { Logger } from "../../helpers/loggerHelper"; import { StatusBarMessageHelper } from "../../helpers/statusBarMessageHelper"; +import { SentryHelper } from "../../helpers/sentryHelper"; import { expect, sinon } from "../setup"; describe("ErrorHandler", () => { let errorHandler: ErrorHandler; let loggerStub: sinon.SinonStubbedInstance; let statusBarMessageHelperStub: sinon.SinonStubbedInstance; + let sentryHelperStub: sinon.SinonStubbedInstance; let sandbox: sinon.SinonSandbox; beforeEach(() => { @@ -18,8 +20,11 @@ describe("ErrorHandler", () => { statusBarMessageHelperStub = { showErrorMessage: sandbox.stub(), } as any; + sentryHelperStub = { + captureException: sandbox.stub(), + } as any; - errorHandler = new ErrorHandler(statusBarMessageHelperStub, loggerStub); + errorHandler = new ErrorHandler(statusBarMessageHelperStub, loggerStub, sentryHelperStub); }); afterEach(() => { diff --git a/tsconfig.json b/tsconfig.json index ca2ac9d..2d0edb5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,15 +27,7 @@ "strictFunctionTypes": true, "strictNullChecks": true, "baseUrl": "./src", - "inlineSources": true, - - // Set `sourceRoot` to "/" to strip the build path prefix - // from generated source code references. - // This improves issue grouping in Sentry. - // Set `sourceRoot` to "/" to strip the build path prefix - // from generated source code references. - // This improves issue grouping in Sentry. - "sourceRoot": "/" + "inlineSources": true }, "include": ["src/**/*.ts", "test/**/*.ts"] }