Skip to content

Commit 599ceef

Browse files
committed
Improve error output on unhandled exceptions (#92)
Before we'd show a stacktrace with minified source code. I also unhid the login command.
1 parent 4be8554 commit 599ceef

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/blink/src/cli/index.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { version } from "../../package.json";
2525
import build from "./build";
2626
import deploy from "./deploy";
2727
import setupSlackApp from "./setup-slack-app";
28+
import * as clack from "@clack/prompts";
2829

2930
// This polyfill is because older versions of NodeJS don't have a global crypto object.
3031
if (!globalThis.crypto) {
@@ -122,14 +123,23 @@ program
122123
.action(asyncEntry(() => import("./chat")));
123124

124125
program
125-
.command("login", {
126-
// This is hidden intentionally.
127-
// The Blink CLI should be primarily open-source,
128-
// and deploying to cloud should be the *only* proprietary
129-
// feature in this CLI.
130-
hidden: true,
131-
})
126+
.command("login")
132127
.description("Log in to the Blink Cloud.")
133128
.action(asyncEntry(() => import("./login")));
134129

130+
// Configure error output
131+
program.configureOutput({
132+
writeErr: (str) => {
133+
// Strip ANSI codes from commander's default error messages
134+
const cleanStr = str.replace(/\x1b\[[0-9;]*m/g, "");
135+
clack.log.error(cleanStr.trim());
136+
},
137+
});
138+
139+
// Global error handler for uncaught errors in command actions
140+
process.on("unhandledRejection", (error: any) => {
141+
clack.log.error(error?.message || String(error));
142+
process.exit(1);
143+
});
144+
135145
program.parse(process.argv);

0 commit comments

Comments
 (0)