feat(@websnacksjs/conventional): initial implementation
`@websnacksjs/conventional` is a cli program which can be used with `husky` & git hooks to enforce that commit messages adhere to the conventional commits standard.
This commit is contained in:
parent
3165625fb7
commit
5f519f54f2
19 changed files with 1446 additions and 1 deletions
28
packages/conventional/src/lib/utils/error.ts
Normal file
28
packages/conventional/src/lib/utils/error.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
export const normalizeError = (error: unknown): Error => {
|
||||
if (!(error instanceof Error)) {
|
||||
error = new Error(`non-Error type thrown: ${JSON.stringify(error)}`);
|
||||
}
|
||||
return error as Error;
|
||||
};
|
||||
|
||||
const errorCauseChain = (error: Error): Error[] => {
|
||||
const causeChain: Error[] = [];
|
||||
let cause = error.cause;
|
||||
while (cause !== undefined) {
|
||||
causeChain.push(normalizeError(cause));
|
||||
|
||||
if (cause instanceof Error) {
|
||||
cause = cause.cause;
|
||||
}
|
||||
}
|
||||
return causeChain;
|
||||
};
|
||||
|
||||
export const formatError = (error: Error): string => {
|
||||
let message = error.message;
|
||||
const causeChain = errorCauseChain(error);
|
||||
for (const cause of causeChain) {
|
||||
message += `: ${cause.message}`;
|
||||
}
|
||||
return message;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue