From 851f57e8fbe72983ba056c1c687cc405938036f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Proch=C3=A1zka?= Date: Wed, 13 Mar 2024 11:42:46 +0100 Subject: [PATCH] Auto detect error in withError --- src/RecordBuilder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/RecordBuilder.php b/src/RecordBuilder.php index c9878dd..9acc3c5 100644 --- a/src/RecordBuilder.php +++ b/src/RecordBuilder.php @@ -85,8 +85,10 @@ public function withNote(?string $note): static } - public function withError(?Throwable $exception, bool $isFinished = false): static + public function withError(?Throwable $exception, bool $isFinished = null): static { + $this->record['finished'] ??= $isFinished ?? !isset($exception); + if (!$exception instanceof Throwable) { return $this; } @@ -96,7 +98,6 @@ public function withError(?Throwable $exception, bool $isFinished = false): stat $className = ucfirst($className); $this->record['note'] = $className.': '.$exception->getMessage(); - $this->record['finished'] ??= $isFinished; return $this; }