-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #869 from BitGo/DX-660-introduce-stacktraces
refactor: introduce standardized error messages and stacktraces
- Loading branch information
Showing
11 changed files
with
129 additions
and
84 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,35 @@ | ||
import * as E from 'fp-ts/Either'; | ||
|
||
/** | ||
* A wrapper around `E.left` that includes a stacktrace. | ||
* @param message the error message | ||
* @returns an `E.left` with the error message and a stacktrace | ||
*/ | ||
export function errorLeft(message: string): E.Either<string, never> { | ||
const stacktrace = new Error().stack!.split('\n').slice(2).join('\n'); | ||
const messageWithStacktrace = message + '\n' + stacktrace; | ||
|
||
return E.left(messageWithStacktrace); | ||
} | ||
|
||
/** | ||
* Testing utility to strip the stacktrace from errors. | ||
* @param errors the list of errors to strip | ||
* @returns the errors without the stacktrace | ||
*/ | ||
export function stripStacktraceOfErrors(errors: string[]) { | ||
return errors.map((e) => e!.split('\n')[0]); | ||
} | ||
|
||
// helper functions for logging | ||
export function logError(message: string): void { | ||
console.error(`[ERROR] ${message}`); | ||
} | ||
|
||
export function logWarn(message: string): void { | ||
console.error(`[WARN] ${message}`); | ||
} | ||
|
||
export function logInfo(message: string): void { | ||
console.error(`[INFO] ${message}`); | ||
} |
Oops, something went wrong.