Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagarjun Sanji committed Sep 23, 2024
1 parent b4a4513 commit d427e00
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/helpers/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/gitHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions src/test/helpers/errorHandler.test.ts
Original file line number Diff line number Diff line change
@@ -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<typeof Logger>;
let statusBarMessageHelperStub: sinon.SinonStubbedInstance<StatusBarMessageHelper>;
let sentryHelperStub: sinon.SinonStubbedInstance<typeof SentryHelper>;
let sandbox: sinon.SinonSandbox;

beforeEach(() => {
Expand All @@ -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(() => {
Expand Down
10 changes: 1 addition & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}

0 comments on commit d427e00

Please sign in to comment.