Add stack trace to unhandled error log message

This change sets the `fullMessage` of the
`showAndLogExceptionWithTelemetry` to include the stack trace. This
makes it possible to find the source of the error rather than only
knowing that a specific error occurred. If the error does not have a
stack trace (which should be rare) the message will be the same as
before.
This commit is contained in:
Koen Vlaswinkel
2023-10-10 15:45:49 +02:00
parent 4ee86c15ad
commit 22f6ac7974

View File

@@ -1164,13 +1164,16 @@ function addUnhandledRejectionListener() {
const message = redactableError(
asError(error),
)`Unhandled error: ${getErrorMessage(error)}`;
const stack = getErrorStack(error);
const fullMessage = stack
? `Unhandled error: ${stack}`
: message.fullMessage;
// Add a catch so that showAndLogExceptionWithTelemetry fails, we avoid
// triggering "unhandledRejection" and avoid an infinite loop
showAndLogExceptionWithTelemetry(
extLogger,
telemetryListener,
message,
).catch((telemetryError: unknown) => {
showAndLogExceptionWithTelemetry(extLogger, telemetryListener, message, {
fullMessage,
}).catch((telemetryError: unknown) => {
void extLogger.log(
`Failed to send error telemetry: ${getErrorMessage(telemetryError)}`,
);