Skip to content

Commit 2f0a348

Browse files
authored
fix(main): don't report user-initiated Ctrl+C aborts as crashes (#3301)
1 parent f333240 commit 2f0a348

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

apps/code/src/main/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,23 @@ if (process.platform !== "win32") {
515515
process.on("SIGHUP", () => handleShutdownSignal("SIGHUP"));
516516
}
517517

518+
// A deliberate Ctrl+C during an interactive prompt makes Node's readline
519+
// SIGINT trap reject the pending prompt with an AbortError (code ABORT_ERR).
520+
// It is user-initiated, not a crash, so don't report it as an uncaught error.
521+
const isAbortError = (error: unknown): boolean =>
522+
error instanceof Error &&
523+
(error.name === "AbortError" ||
524+
(error as NodeJS.ErrnoException).code === "ABORT_ERR");
525+
518526
process.on("uncaughtException", (error) => {
519527
if (error.message === "write EIO") {
520528
log.transports.console.level = false;
521529
return;
522530
}
531+
if (isAbortError(error)) {
532+
log.debug("Ignoring user-initiated abort", error);
533+
return;
534+
}
523535
log.error("Uncaught exception", error);
524536
posthogNodeAnalytics.captureException(error, {
525537
source: "main",
@@ -528,6 +540,10 @@ process.on("uncaughtException", (error) => {
528540
});
529541

530542
process.on("unhandledRejection", (reason) => {
543+
if (isAbortError(reason)) {
544+
log.debug("Ignoring user-initiated abort", reason);
545+
return;
546+
}
531547
log.error("Unhandled rejection", reason);
532548
const error = reason instanceof Error ? reason : new Error(String(reason));
533549
posthogNodeAnalytics.captureException(error, {

0 commit comments

Comments
 (0)