fix: improved unhandled error logging
This commit is contained in:
parent
1f44a3de34
commit
fa96e30a3a
2 changed files with 33 additions and 1 deletions
|
|
@ -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)),
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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]";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue