diff --git a/src/DataBuilder.php b/src/DataBuilder.php index 291f6426..4096d5a5 100644 --- a/src/DataBuilder.php +++ b/src/DataBuilder.php @@ -462,18 +462,25 @@ public function makeTrace( ?string $classOverride = null, string|Stringable $message = null, ): Trace { + $frames = array(); if ($this->captureErrorStacktraces) { $frames = $this->makeFrames($exception, $includeContext); - } else { - $frames = array(); + } + + $exceptionMessage = $exception->getMessage(); + $description = $message; + + // If a message is explicitly set when calling the logger, use that. Otherwise, use the exception's message. + if (null !== $message) { + $exceptionMessage = $message; + $description = $exception->getMessage(); } - $excInfo = new ExceptionInfo( + return new Trace($frames, new ExceptionInfo( $classOverride ?: get_class($exception), - $exception->getMessage(), - $message - ); - return new Trace($frames, $excInfo); + $exceptionMessage, + $description, + )); } public function makeFrames($exception, $includeContext) diff --git a/tests/DataBuilderTest.php b/tests/DataBuilderTest.php index ea2b7a12..5e7b3172 100644 --- a/tests/DataBuilderTest.php +++ b/tests/DataBuilderTest.php @@ -706,8 +706,8 @@ public function testExceptionInContext(): void $this->assertSame( array( 'class' => 'Exception', - 'message' => 'testing exception', - 'description' => 'testing', + 'message' => 'testing', + 'description' => 'testing exception', ), $output['body']['trace']['exception'], );