Skip to content

Commit

Permalink
Catch throwables
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Jul 13, 2017
1 parent e9ac7ca commit cbed3da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public function callRpc($target, $payload)
throw new \Exception('RPC must return promise');
} catch (\Exception $exception) {
return new RejectedPromise($exception);
} catch (\Throwable $exception) {
return new RejectedPromise($exception);
}
}

Expand Down Expand Up @@ -300,6 +302,8 @@ protected function iterateMessages(array $messages, $source)
$messageFactory::fromLine($message, $this->options['lineOptions'])->handle($this, $source);
} catch (\Exception $exception) {
$this->emit('error', [$exception, $this]);
} catch (\Throwable $exception) {
$this->emit('error', [$exception, $this]);
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ function (Payload $payload) {
*/
public static function create(LoopInterface $loop, Messenger $messenger)
{
try {
return new Process($loop, $messenger);
} catch (\Exception $exeption) {
$reject = function ($exeption) use ($messenger, $loop) {
$messenger->error(MessagesFactory::error([
'message' => $exeption->getMessage(),
'code' => $exeption->getCode(),
Expand All @@ -62,6 +60,13 @@ public static function create(LoopInterface $loop, Messenger $messenger)
$loop->addTimer(1, function () use ($loop) {
$loop->stop();
});
};
try {
return new Process($loop, $messenger);
} catch (\Exception $exeption) {
$reject($exeption);
} catch (\Throwable $exeption) {
$reject($exeption);
}
}

Expand Down

0 comments on commit cbed3da

Please sign in to comment.