2016-12-30 02:16:04 +01:00
|
|
|
<?php
|
2015-08-27 16:10:08 +02:00
|
|
|
|
2016-08-23 23:47:40 +02:00
|
|
|
namespace Amp\Parallel\Worker\Internal;
|
2015-08-27 16:10:08 +02:00
|
|
|
|
2016-08-21 17:33:39 +02:00
|
|
|
use Amp\Failure;
|
2016-08-23 23:47:40 +02:00
|
|
|
use Amp\Parallel\TaskException;
|
2017-01-09 18:11:25 +01:00
|
|
|
use AsyncInterop\Promise;
|
2016-08-21 17:33:39 +02:00
|
|
|
|
2016-09-07 18:38:46 +02:00
|
|
|
class TaskFailure extends TaskResult {
|
2016-08-21 17:33:39 +02:00
|
|
|
/** @var string */
|
2015-08-27 16:10:08 +02:00
|
|
|
private $type;
|
|
|
|
|
2016-08-21 17:33:39 +02:00
|
|
|
/** @var string */
|
2015-08-27 16:10:08 +02:00
|
|
|
private $message;
|
|
|
|
|
2016-08-21 17:33:39 +02:00
|
|
|
/** @var int */
|
2015-08-27 16:10:08 +02:00
|
|
|
private $code;
|
|
|
|
|
2016-08-21 17:33:39 +02:00
|
|
|
/** @var array */
|
2015-08-27 16:10:08 +02:00
|
|
|
private $trace;
|
|
|
|
|
2016-08-21 17:33:39 +02:00
|
|
|
public function __construct(string $id, \Throwable $exception) {
|
2016-09-07 18:38:46 +02:00
|
|
|
parent::__construct($id);
|
2016-09-02 01:10:52 +02:00
|
|
|
$this->type = \get_class($exception);
|
2015-08-27 16:10:08 +02:00
|
|
|
$this->message = $exception->getMessage();
|
|
|
|
$this->code = $exception->getCode();
|
|
|
|
$this->trace = $exception->getTraceAsString();
|
|
|
|
}
|
2016-08-21 17:33:39 +02:00
|
|
|
|
2016-11-15 00:43:44 +01:00
|
|
|
public function promise(): Promise {
|
2016-08-21 17:33:39 +02:00
|
|
|
return new Failure(new TaskException(
|
2016-08-30 20:19:10 +02:00
|
|
|
$this->type,
|
2015-08-27 16:10:08 +02:00
|
|
|
sprintf('Uncaught exception in worker of type "%s" with message "%s"', $this->type, $this->message),
|
|
|
|
$this->code,
|
|
|
|
$this->trace
|
2016-08-21 17:33:39 +02:00
|
|
|
));
|
2015-08-27 16:10:08 +02:00
|
|
|
}
|
|
|
|
}
|