-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add error handling when stats file is outdated
- Loading branch information
Showing
4 changed files
with
59 additions
and
9 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
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,38 @@ | ||
export class AtlasError extends Error { | ||
/** A property to determine if any of the extended errors are atlas-specific errors */ | ||
public readonly type = 'AtlasError'; | ||
/** The error (class) name */ | ||
public readonly name: string; | ||
/** The error code, specifically for these types of errors */ | ||
public readonly code?: string; | ||
|
||
constructor(code: string, message = '', options?: ErrorOptions) { | ||
super(message, options); | ||
this.name = this.constructor.name; | ||
this.code = code; | ||
} | ||
} | ||
|
||
export class AtlasValidationError extends AtlasError { | ||
constructor( | ||
code: 'STATS_FILE_NOT_FOUND' | 'STATS_FILE_INCOMPATIBLE', | ||
public readonly statsFile: string, | ||
public readonly incompatibleVersion?: string | ||
) { | ||
super( | ||
code, | ||
code === 'STATS_FILE_NOT_FOUND' | ||
? `Stats file not found: ${statsFile}` | ||
: `Stats file is incompatible with this version.` | ||
); | ||
} | ||
} | ||
|
||
export function handleError(error: Error) { | ||
if (error instanceof AtlasError) { | ||
console.error(`${error.message} (${error.code})`); | ||
return true; | ||
} | ||
|
||
throw error; | ||
} |