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