-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
51 lines (46 loc) · 1.44 KB
/
mod.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
41
42
43
44
45
46
47
48
49
50
51
import { Sentry } from "./deps.ts";
import { COMMIT } from "./version.ts";
import { ApiClientError, AppError } from "./errors.ts";
import { root } from "./commands/mod.ts";
import { fmt } from "./zcli.ts";
import { cursorShow } from "./deps.ts";
import { print } from "./lib/print.ts";
if (import.meta.main) {
// Initialize Sentry
Sentry.init({
dsn:
"https://[email protected]/4504454143475712",
release: COMMIT,
tracesSampleRate: 0,
});
Deno.addSignalListener("SIGINT", async () => {
await print(cursorShow());
Deno.exit();
});
try {
await root.execute();
} catch (err) {
// Clean up the cursor before exiting in case we removed it somewhere.
print(cursorShow());
// Catch known errors and exit with the appropriate code.
if (err instanceof ApiClientError) {
console.error(`${fmt.colors.bold("Network Error")}\n%s`, err.message);
Deno.exit(err.exitCode);
} else if (err instanceof AppError) {
console.error(err.message);
Deno.exit(err.exitCode);
}
Sentry.captureException(err);
await Sentry.flush();
console.error(err);
console.error(`${fmt.colors.bold("Runtime Error")}\n%s`, err.message);
console.error(
`\n${
fmt.colors.yellow(
"Please file a bug report including the above message:",
)
}\n → https://github.com/Paperspace/cli/issues/new`,
);
Deno.exit(1);
}
}