-
-
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.
- Loading branch information
Showing
7 changed files
with
65 additions
and
5 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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/** | ||
* Exit codes enum when an error occurs. | ||
*/ | ||
export enum ExitCodes { | ||
Success = 0, | ||
NotFound = 243, | ||
|
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 |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import { ExitCodes } from './enums.ts'; | ||
import { error } from './logger.ts'; | ||
import { ExitCodes } from './enums.ts'; | ||
|
||
/** | ||
* Custom error class for creating errors | ||
* and logging and exiting with {@link DenohError.logAndExit} function. | ||
*/ | ||
export class DenohError extends Error { | ||
constructor(message: string, public exitCode?: ExitCodes) { | ||
super(message); | ||
|
||
this.name = 'DenohError'; | ||
} | ||
|
||
/** | ||
* Logs the error to the console and exists with | ||
* specified exit code. | ||
*/ | ||
logAndExit() { | ||
error(this.message); | ||
return Deno.exit(this.exitCode ?? 1); | ||
return Deno.exit(this.exitCode ?? ExitCodes.UnknownError); | ||
} | ||
} |
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
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