-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.ts
40 lines (33 loc) · 880 Bytes
/
log.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
34
35
36
37
38
39
40
import chalk from "chalk";
import { BoxError, CommandError } from "./src/error.ts";
console.info = (...data) => {
console.log(`${chalk.blue.bold("info")}:`, ...data);
};
console.warn = (...data) => {
console.log(`${chalk.yellow.bold("warn")}:`, ...data);
};
console.error = (...data) => {
console.log(`${chalk.red.bold("error")}:`, ...data);
};
function logError(error: Error) {
if (error instanceof CommandError) {
logCommandError(error);
}
if (error instanceof BoxError) {
logBoxError(error);
}
console.error(error);
Deno.exit();
}
function logCommandError(error: CommandError) {
console.error(
`${error.message}${error.usage ? "\n\nUsage: " + error.usage : ""}`
);
Deno.exit();
}
function logBoxError(error: BoxError) {
console.error(error.message);
if (error.hint) console.info(error.hint);
Deno.exit();
}
export { logError };