Skip to content

Commit 96ff283

Browse files
committed
refactor(errors): remove ChangelogFileNotFoundError
- Improved error handling in changelog service. - Replaced custom error with FileNotFoundError. - Simplified error handling logic. - Removed unnecessary error class. - Updated tests to reflect changes.
1 parent cf27a82 commit 96ff283

3 files changed

Lines changed: 4 additions & 16 deletions

File tree

src/errors.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,3 @@ export class InvalidManifestError extends CustomError {
4343
super(message, 'InvalidManifestError');
4444
}
4545
}
46-
47-
/**
48-
* Error thrown when the changelog file is not found.
49-
*/
50-
export class ChangelogFileNotFoundError extends CustomError {
51-
constructor(message: string) {
52-
super(message, 'ChangelogFileNotFoundError');
53-
}
54-
}

src/services/changelogService.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ export class ChangelogService {
5454
let existingChangelog: string;
5555
try {
5656
existingChangelog = await this.fileHandler.readFile(changelogPath);
57-
} catch (error: any) {
58-
if (error.code === 'ENOENT') {
59-
throw new FileNotFoundError(
60-
`Changelog file not found at ${changelogPath}`,
61-
);
57+
} catch (error: unknown) {
58+
if (error instanceof FileNotFoundError) {
59+
throw new FileNotFoundError(`Changelog file not found at ${changelogPath}`);
6260
}
6361
throw error;
6462
}

tests/services/changelogService.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ describe('ChangelogService', () => {
6969

7070
it('should throw FileNotFoundError if changelog file does not exist', async () => {
7171
const changelogPath = 'CHANGELOG.md';
72-
const error = new Error('File not found') as any;
73-
error.code = 'ENOENT';
72+
const error = new FileNotFoundError('File not found');
7473
vi.spyOn(fileHandler, 'readFile').mockRejectedValue(error);
7574

7675
await expect(changelogService.updateChangelog('## v1.1.0\n\n- New feature')).rejects.toThrow(

0 commit comments

Comments
 (0)