1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-13 01:27:24 +01:00
parallel/lib/Sync/ExitFailure.php

49 lines
1.1 KiB
PHP
Raw Normal View History

2016-12-30 02:16:04 +01:00
<?php
2015-08-07 01:59:25 +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;
/** @var int|string */
2015-08-07 01:59:25 +02:00
private $code;
/** @var string[] */
2015-08-07 01:59:25 +02:00
private $trace;
/** @var self|null */
private $previous;
2018-10-07 16:50:45 +02:00
public function __construct(\Throwable $exception)
{
$this->type = \get_class($exception);
2015-08-07 01:59:25 +02:00
$this->message = $exception->getMessage();
$this->code = $exception->getCode();
$this->trace = flattenThrowableBacktrace($exception);
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()
{
throw $this->createException();
}
2020-02-11 18:06:30 +01:00
private function createException(): ContextPanicError
{
$previous = $this->previous ? $this->previous->createException() : null;
2020-02-11 18:06:30 +01:00
return new ContextPanicError($this->type, $this->message, $this->code, $this->trace, $previous);
2015-08-07 01:59:25 +02:00
}
2017-05-18 09:51:31 +02:00
}