-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.ts
33 lines (28 loc) · 896 Bytes
/
logger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type * as typia from 'typia';
import process from 'node:process';
import { consola, type ConsolaInstance } from 'consola';
import { name } from '../package.json';
export const logger: ConsolaInstance = consola.withTag(name);
/**
* Throw an error and exit the process
* @internal
*/
export function _throwError(message: string): never {
logger.error(message);
if (process.env.NODE_ENV === 'test') {
throw new Error(message);
}
process.exit(1);
}
/**
* Handle typia validation error
*/
export function _typiaErrorHandler<T>(validation: typia.IValidation<T>): never | typia.IValidation.ISuccess<T> {
if (!validation.success) {
const message = validation.errors.map(({ path, expected, value }) =>
`${path} is invalid. Ecpected type is ${expected}, but got ${value}`,
).join('\n');
return _throwError(`Invalid JSR configuration: ${message}`);
}
return validation;
}