-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): improve error handling with more custom Error instances
- Loading branch information
1 parent
8dadfe9
commit 30a448b
Showing
6 changed files
with
123 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@emigrate/cli': minor | ||
--- | ||
|
||
Improve error handling by making more granular custom Error instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { type MigrationHistoryEntry, type MigrationMetadata } from '@emigrate/plugin-tools/types'; | ||
|
||
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' }); | ||
|
||
export class EmigrateError extends Error { | ||
constructor( | ||
public code: string, | ||
message: string, | ||
options?: ErrorOptions, | ||
) { | ||
super(message, options); | ||
} | ||
} | ||
|
||
export class ShowUsageError extends EmigrateError {} | ||
|
||
export class MissingOptionError extends ShowUsageError { | ||
constructor(public option: string | string[]) { | ||
super('ERR_MISSING_OPT', `Missing required option: ${Array.isArray(option) ? formatter.format(option) : option}`); | ||
} | ||
} | ||
|
||
export class MissingArgumentsError extends ShowUsageError { | ||
constructor(public argument: string) { | ||
super('ERR_MISSING_ARGS', `Missing required argument: ${argument}`); | ||
} | ||
} | ||
|
||
export class BadOptionError extends ShowUsageError { | ||
constructor( | ||
public option: string, | ||
message: string, | ||
) { | ||
super('ERR_BAD_OPT', message); | ||
} | ||
} | ||
|
||
export class UnexpectedError extends EmigrateError { | ||
constructor(message: string, options?: ErrorOptions) { | ||
super('ERR_UNEXPECTED', message, options); | ||
} | ||
} | ||
|
||
export class MigrationHistoryError extends EmigrateError { | ||
constructor( | ||
message: string, | ||
public entry: MigrationHistoryEntry, | ||
) { | ||
super('ERR_MIGRATION_HISTORY', message); | ||
} | ||
} | ||
|
||
export class MigrationLoadError extends EmigrateError { | ||
constructor( | ||
message: string, | ||
public metadata: MigrationMetadata, | ||
options?: ErrorOptions, | ||
) { | ||
super('ERR_MIGRATION_LOAD', message, options); | ||
} | ||
} | ||
|
||
export class MigrationRunError extends EmigrateError { | ||
constructor( | ||
message: string, | ||
public metadata: MigrationMetadata, | ||
options?: ErrorOptions, | ||
) { | ||
super('ERR_MIGRATION_RUN', message, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters