Skip to content

Commit 7cb77e0

Browse files
Refactor error classes.
Introduced a new base class `AppError` to standardize error handling. Updated `FileUtilsError` and `TargetUnitRepositoryError` to derive from `AppError`, simplifying their structure and removing redundant code. Removed tests for deprecated error properties (`cause`), aligning with the new error design.
1 parent 022ed8d commit 7cb77e0

File tree

6 files changed

+18
-44
lines changed

6 files changed

+18
-44
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class AppError extends Error {
2+
constructor(message: string, name: string) {
3+
super(message);
4+
this.name = name;
5+
if (Error.captureStackTrace) {
6+
Error.captureStackTrace(this, this.constructor);
7+
}
8+
}
9+
}

workers/main/src/common/errors/FileUtilsError.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,4 @@ describe('FileUtilsError', () => {
99
expect(err.message).toBe('test message');
1010
expect(err.name).toBe('FileUtilsError');
1111
});
12-
13-
it('should set the cause if provided', () => {
14-
const cause = new Error('root cause');
15-
const err = new FileUtilsError('with cause', cause);
16-
17-
expect(err.cause).toBe(cause);
18-
});
19-
20-
it('should not set cause if not provided', () => {
21-
const err = new FileUtilsError('no cause');
22-
23-
expect(err.cause).toBeUndefined();
24-
});
2512
});
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
export class FileUtilsError extends Error {
2-
public cause?: unknown;
1+
import { AppError } from './AppError';
32

4-
constructor(message: string, cause?: unknown) {
5-
super(message);
6-
this.name = 'FileUtilsError';
7-
this.cause = cause;
8-
if (Error.captureStackTrace) {
9-
Error.captureStackTrace(this, FileUtilsError);
10-
}
3+
export class FileUtilsError extends AppError {
4+
constructor(message: string) {
5+
super(message, 'FileUtilsError');
116
}
127
}

workers/main/src/common/errors/TargetUnitRepositoryError.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,4 @@ describe('TargetUnitRepositoryError', () => {
99
expect(err.message).toBe('test message');
1010
expect(err.name).toBe('TargetUnitRepositoryError');
1111
});
12-
13-
it('should set the cause if provided', () => {
14-
const cause = new Error('root cause');
15-
const err = new TargetUnitRepositoryError('with cause', cause);
16-
17-
expect(err.cause).toBe(cause);
18-
});
19-
20-
it('should not set cause if not provided', () => {
21-
const err = new TargetUnitRepositoryError('no cause');
22-
23-
expect(err.cause).toBeUndefined();
24-
});
2512
});
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
export class TargetUnitRepositoryError extends Error {
2-
public cause?: unknown;
1+
import { AppError } from './AppError';
32

4-
constructor(message: string, cause?: unknown) {
5-
super(message);
6-
this.name = 'TargetUnitRepositoryError';
7-
this.cause = cause;
8-
if (Error.captureStackTrace) {
9-
Error.captureStackTrace(this, TargetUnitRepositoryError);
10-
}
3+
export class TargetUnitRepositoryError extends AppError {
4+
constructor(message: string) {
5+
super(message, 'TargetUnitRepositoryError');
116
}
127
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './AppError';
12
export * from './FileUtilsError';
23
export * from './TargetUnitRepositoryError';

0 commit comments

Comments
 (0)