From d4b8415392b99a6b685f79879e1ba740b9b84b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bok?= Date: Sun, 14 May 2023 21:40:53 +0200 Subject: [PATCH] Add context to process timeout exception --- .../ChildProcessTimeoutException.php | 36 +++++++++++++++++++ src/ValueObject/ParallelProcess.php | 5 ++- 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/ValueObject/ChildProcessTimeoutException.php diff --git a/src/ValueObject/ChildProcessTimeoutException.php b/src/ValueObject/ChildProcessTimeoutException.php new file mode 100644 index 0000000..7cacd66 --- /dev/null +++ b/src/ValueObject/ChildProcessTimeoutException.php @@ -0,0 +1,36 @@ +context = $context; + } + + /** + * @return mixed[] + */ + public function getContext(): array + { + return $this->context; + } +} diff --git a/src/ValueObject/ParallelProcess.php b/src/ValueObject/ParallelProcess.php index b7a0362..ae04758 100644 --- a/src/ValueObject/ParallelProcess.php +++ b/src/ValueObject/ParallelProcess.php @@ -6,7 +6,6 @@ use Clue\React\NDJson\Decoder; use Clue\React\NDJson\Encoder; -use Exception; use React\ChildProcess\Process; use React\EventLoop\LoopInterface; use React\EventLoop\TimerInterface; @@ -98,11 +97,11 @@ public function request(array $data): void { $this->cancelTimer(); $this->encoder->write($data); - $this->timer = $this->loop->addTimer($this->timetoutInSeconds, function (): void { + $this->timer = $this->loop->addTimer($this->timetoutInSeconds, function () use ($data): void { $onError = $this->onError; $errorMessage = sprintf('Child process timed out after %d seconds', $this->timetoutInSeconds); - $onError(new Exception($errorMessage)); + $onError(new ChildProcessTimeoutException($errorMessage, $data)); }); }