Skip to content

Commit

Permalink
Attach ExitFailure exception as previous exception
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 21, 2024
1 parent 4592406 commit f1cdbdf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Context/ProcessContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,16 @@ public function join(?Cancellation $cancellation = null): mixed
$data = $this->receiveExitResult($cancellation);

$code = $this->process->join();
if ($code !== 0 && !($data instanceof ExitFailure)) {
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));
}
}
}

/**
Expand Down

0 comments on commit f1cdbdf

Please sign in to comment.