mirror of
https://github.com/stack-auth/stack.git
synced 2026-07-20 21:29:36 +08:00
fix(cli): await sentry sink before fatal capture
Co-Authored-By: mantra <mantra@stack-auth.com>
This commit is contained in:
parent
58a5ba223d
commit
bc49ce80bf
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user