-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathExitFailure.php
More file actions
73 lines (58 loc) · 1.86 KB
/
ExitFailure.php
File metadata and controls
73 lines (58 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php declare(strict_types=1);
namespace Amp\Parallel\Context\Internal;
use Amp\Parallel\Context\ContextException;
use Amp\Parallel\Context\ContextPanicError;
use function Amp\Parallel\Context\flattenThrowableBacktrace;
/**
* @internal
* @psalm-import-type FlattenedTrace from ContextPanicError
* @template-implements ExitResult<never>
*/
final class ExitFailure implements ExitResult
{
/** @var class-string<\Throwable> */
private readonly string $className;
private readonly string $message;
private readonly int|string $code;
private readonly string $file;
private readonly int $line;
/** @var FlattenedTrace */
private readonly array $trace;
private readonly ?self $previous;
public function __construct(\Throwable $exception)
{
$this->className = \get_class($exception);
$this->message = $exception->getMessage();
$this->code = $exception->getCode();
$this->file = $exception->getFile();
$this->line = $exception->getLine();
$this->trace = flattenThrowableBacktrace($exception);
$previous = $exception->getPrevious();
$this->previous = $previous ? new self($previous) : null;
}
/**
* @throws ContextException
*/
#[\Override]
public function getResult(): never
{
$exception = $this->createException();
throw new ContextException(
'Process exited with an uncaught exception: ' . $exception->getMessage(),
previous: $exception,
);
}
private function createException(): ContextPanicError
{
$previous = $this->previous?->createException();
return new ContextPanicError(
$this->className,
$this->message,
$this->code,
$this->file,
$this->line,
$this->trace,
$previous,
);
}
}