diff --git a/src/Result/Err.php b/src/Result/Err.php index 257db0d..27e3bae 100644 --- a/src/Result/Err.php +++ b/src/Result/Err.php @@ -46,6 +46,10 @@ public function expect(string|Throwable $message): mixed throw $message; } + if ($this->err instanceof Throwable) { + throw new RuntimeException($message, previous: $this->err); + } + throw new RuntimeException($message); } diff --git a/src/Result/Ok.php b/src/Result/Ok.php index 83f61bb..7462bf7 100644 --- a/src/Result/Ok.php +++ b/src/Result/Ok.php @@ -47,7 +47,11 @@ public function expect(string|Throwable $message): mixed public function expectErr(Throwable|string $message): mixed { - throw $message instanceof Throwable ? $message : new RuntimeException($message); + if ($message instanceof Throwable) { + throw $message; + } + + throw new RuntimeException($message); } public function inspect(callable $f): Result