2016-12-30 02:16:04 +01:00
|
|
|
<?php
|
2015-08-07 01:59:25 +02:00
|
|
|
|
2017-07-29 00:34:24 +02:00
|
|
|
namespace Amp\Parallel\Sync;
|
2015-08-07 01:59:25 +02:00
|
|
|
|
2018-10-21 17:54:46 +02:00
|
|
|
final class ExitFailure implements ExitResult
|
2018-10-07 16:50:45 +02:00
|
|
|
{
|
2016-08-26 17:10:03 +02:00
|
|
|
/** @var string */
|
2015-08-07 01:59:25 +02:00
|
|
|
private $type;
|
|
|
|
|
2016-08-26 17:10:03 +02:00
|
|
|
/** @var string */
|
2015-08-07 01:59:25 +02:00
|
|
|
private $message;
|
|
|
|
|
2017-11-10 18:32:15 +01:00
|
|
|
/** @var int|string */
|
2015-08-07 01:59:25 +02:00
|
|
|
private $code;
|
|
|
|
|
2016-08-26 17:10:03 +02:00
|
|
|
/** @var array */
|
2015-08-07 01:59:25 +02:00
|
|
|
private $trace;
|
|
|
|
|
2019-01-26 00:53:19 +01:00
|
|
|
/** @var self|null */
|
|
|
|
private $previous;
|
|
|
|
|
2018-10-07 16:50:45 +02:00
|
|
|
public function __construct(\Throwable $exception)
|
|
|
|
{
|
2016-09-02 06:38:00 +02:00
|
|
|
$this->type = \get_class($exception);
|
2015-08-07 01:59:25 +02:00
|
|
|
$this->message = $exception->getMessage();
|
|
|
|
$this->code = $exception->getCode();
|
|
|
|
$this->trace = $exception->getTraceAsString();
|
2019-01-26 00:53:19 +01:00
|
|
|
|
|
|
|
if ($previous = $exception->getPrevious()) {
|
|
|
|
$this->previous = new self($previous);
|
|
|
|
}
|
2015-08-07 01:59:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2018-10-07 16:50:45 +02:00
|
|
|
public function getResult()
|
|
|
|
{
|
2019-01-26 00:53:19 +01:00
|
|
|
throw $this->createException();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createException(): PanicError
|
|
|
|
{
|
|
|
|
$previous = $this->previous ? $this->previous->createException() : null;
|
|
|
|
|
|
|
|
return new PanicError(
|
2016-09-02 06:38:00 +02:00
|
|
|
$this->type,
|
2016-08-18 18:04:48 +02:00
|
|
|
\sprintf(
|
2019-03-02 16:19:00 +01:00
|
|
|
'Uncaught %s in worker with message "%s" and code "%s"; use %s::getPanicTrace() '
|
|
|
|
. 'for the stack trace in the context',
|
2015-08-27 16:10:08 +02:00
|
|
|
$this->type,
|
2017-11-10 18:32:15 +01:00
|
|
|
$this->message,
|
2019-03-02 16:19:00 +01:00
|
|
|
$this->code,
|
|
|
|
PanicError::class
|
2015-08-27 16:10:08 +02:00
|
|
|
),
|
2019-01-26 00:53:19 +01:00
|
|
|
$this->trace,
|
|
|
|
$previous
|
2015-08-07 01:59:25 +02:00
|
|
|
);
|
|
|
|
}
|
2017-05-18 09:51:31 +02:00
|
|
|
}
|