From 5113111de02796a782f5d90767455e7391cca190 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 21 Dec 2024 02:56:09 +0100 Subject: [PATCH] Prevent silencing ExitFailure in ProcessContext->join() (#207) --- src/Context/ProcessContext.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Context/ProcessContext.php b/src/Context/ProcessContext.php index 64fca30..c0c97ed 100644 --- a/src/Context/ProcessContext.php +++ b/src/Context/ProcessContext.php @@ -281,11 +281,16 @@ public function join(?Cancellation $cancellation = null): mixed $data = $this->receiveExitResult($cancellation); $code = $this->process->join(); - if ($code !== 0) { - throw new ContextException(\sprintf("Context exited with code %d", $code)); - } - return $data->getResult(); + try { + return $data->getResult(); + } finally { + if ($code !== 0) { + // If an ExitFailure throws above, the exception will be automatically attached as the previous + // exception on the instance thrown below. + throw new ContextException(\sprintf("Context exited with code %d", $code)); + } + } } /**