fix: improved unhandled error logging

This commit is contained in:
Nate 2025-11-26 11:03:48 -08:00
parent 1f44a3de34
commit fa96e30a3a
2 changed files with 33 additions and 1 deletions

View file

@ -91,7 +91,26 @@ export function shouldShowExitMessage(): boolean {
// Add global error handlers to prevent uncaught errors from crashing the process
process.on("unhandledRejection", (reason, promise) => {
logger.error("Unhandled Rejection at:", { promise, reason });
// Extract useful information from the reason
const errorDetails = {
promiseString: String(promise),
reasonType: typeof reason,
reasonConstructor: reason?.constructor?.name,
};
// If reason is an Error, use it directly for better stack traces
if (reason instanceof Error) {
logger.error("Unhandled Promise Rejection", reason, errorDetails);
} else {
// Convert non-Error reasons to Error for consistent handling
const error = new Error(`Unhandled rejection: ${String(reason)}`);
logger.error("Unhandled Promise Rejection", error, {
...errorDetails,
originalReason: String(reason),
});
}
// Sentry capture remains the same
sentryService.captureException(
reason instanceof Error ? reason : new Error(String(reason)),
{

View file

@ -44,6 +44,19 @@ function createReplacer() {
seen.add(value);
}
// Handle Error objects explicitly - extract useful properties
if (value instanceof Error) {
const errorObj: any = {
name: value.name,
message: value.message,
stack: value.stack,
};
if (value.cause) {
errorObj.cause = value.cause;
}
return errorObj;
}
// Handle functions
if (typeof value === "function") {
return "[Function]";