fix(cli): await sentry sink before fatal capture

Co-Authored-By: mantra <mantra@stack-auth.com>
This commit is contained in:
Devin AI 2026-07-14 02:23:13 +00:00
parent 58a5ba223d
commit bc49ce80bf
2 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { flushSentry, initSentry } from "./lib/sentry.js";
import { captureFatalError, initSentry } from "./lib/sentry.js";
initSentry();
import { Command } from "commander";
@ -49,9 +49,7 @@ async function main() {
console.error(`Error: ${err.message}`);
process.exit(1);
}
const { captureError } = await import("@hexclave/shared/dist/utils/errors");
captureError("stack-cli-fatal", err);
await flushSentry(2000);
await captureFatalError("stack-cli-fatal", err);
console.error(err);
process.exit(1);
}

View File

@ -74,6 +74,18 @@ export function initSentry(): void {
}));
}
export async function captureFatalError(location: string, error: unknown, timeoutMs = 2000): Promise<void> {
try {
// Registration is asynchronous to keep startup fast, so fatal reporting must wait for the sink.
await registrationPromise;
const { captureError } = await import("@hexclave/shared/dist/utils/errors");
captureError(location, error);
await flushSentry(timeoutMs);
} catch {
// Preserve the original fatal error path if optional Sentry reporting fails.
}
}
export async function flushSentry(timeoutMs = 2000): Promise<void> {
await registrationPromise;
await capturePromise;