1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-30 04:39:01 +01:00

Add code to exception message, addresses #21

Code is no longer passed to exception constructor in parent context.
This commit is contained in:
Aaron Piotrowski 2017-11-10 11:32:15 -06:00
parent 0e71b18197
commit 26e826a05f
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
6 changed files with 24 additions and 28 deletions

View File

@ -14,15 +14,11 @@ class PanicError extends \Error {
*
* @param string $name The uncaught exception class.
* @param string $message The panic message.
* @param mixed $code The panic code.
* @param string $trace The panic stack trace.
*/
public function __construct(string $name, string $message = '', $code = 0, string $trace = '') {
public function __construct(string $name, string $message = '', string $trace = '') {
parent::__construct($message);
// Code might also be a string, because PDO, so don't pass to parent constructor, but assign directly.
// See https://github.com/amphp/parallel/issues/19.
$this->code = $code;
$this->name = $name;
$this->trace = $trace;
}

View File

@ -14,8 +14,8 @@ interface Channel {
* @throws \Amp\Parallel\StatusError Thrown if the context has not been started.
* @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context
* unexpectedly ends.
* @throws \Amp\Parallel\ChannelException If receiving from the channel fails.
* @throws \Amp\Parallel\SerializationException If unserializing the data fails.
* @throws \Amp\Parallel\Sync\ChannelException If receiving from the channel fails.
* @throws \Amp\Parallel\Sync\SerializationException If unserializing the data fails.
*/
public function receive(): Promise;
@ -27,9 +27,9 @@ interface Channel {
* @throws \Amp\Parallel\StatusError Thrown if the context has not been started.
* @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context
* unexpectedly ends.
* @throws \Amp\Parallel\ChannelException If sending on the channel fails.
* @throws \Amp\Parallel\Sync\ChannelException If sending on the channel fails.
* @throws \Error If an ExitResult object is given.
* @throws \Amp\Parallel\SerializationException If serializing the data fails.
* @throws \Amp\Parallel\Sync\SerializationException If serializing the data fails.
*/
public function send($data): Promise;
}

View File

@ -11,7 +11,7 @@ class ExitFailure implements ExitResult {
/** @var string */
private $message;
/** @var int */
/** @var int|string */
private $code;
/** @var array */
@ -31,11 +31,11 @@ class ExitFailure implements ExitResult {
throw new PanicError(
$this->type,
\sprintf(
'Uncaught exception in execution context of type "%s" with message "%s"',
'Uncaught exception in execution context of type "%s" with message "%s" and code "%s"',
$this->type,
$this->message
$this->message,
$this->code
),
$this->code,
$this->trace
);
}

View File

@ -21,7 +21,7 @@ class TaskFailure extends TaskResult {
/** @var string */
private $message;
/** @var int */
/** @var int|string */
private $code;
/** @var array */
@ -41,8 +41,12 @@ class TaskFailure extends TaskResult {
case self::PARENT_ERROR:
$exception = new TaskError(
$this->type,
sprintf('Uncaught Error in worker of type "%s" with message "%s"', $this->type, $this->message),
$this->code,
sprintf(
'Uncaught Error in worker of type "%s" with message "%s" and code "%s"',
$this->type,
$this->message,
$this->code
),
$this->trace
);
break;
@ -50,8 +54,12 @@ class TaskFailure extends TaskResult {
default:
$exception = new TaskException(
$this->type,
sprintf('Uncaught Exception in worker of type "%s" with message "%s"', $this->type, $this->message),
$this->code,
sprintf(
'Uncaught Exception in worker of type "%s" with message "%s" and code "%s"',
$this->type,
$this->message,
$this->code
),
$this->trace
);
}

View File

@ -12,15 +12,11 @@ class TaskError extends \Error {
/**
* @param string $name The exception class name.
* @param string $message The panic message.
* @param mixed $code The panic code.
* @param string $trace The panic stack trace.
*/
public function __construct(string $name, string $message = '', $code = 0, string $trace = '') {
public function __construct(string $name, string $message = '', string $trace = '') {
parent::__construct($message);
// Code might also be a string, because PDO, so don't pass to parent constructor, but assign directly.
// See https://github.com/amphp/parallel/issues/19.
$this->code = $code;
$this->name = $name;
$this->trace = $trace;
}

View File

@ -12,15 +12,11 @@ class TaskException extends \Exception {
/**
* @param string $name The exception class name.
* @param string $message The panic message.
* @param mixed $code The panic code.
* @param string $trace The panic stack trace.
*/
public function __construct(string $name, string $message = '', $code = 0, string $trace = '') {
public function __construct(string $name, string $message = '', string $trace = '') {
parent::__construct($message);
// Code might also be a string, because PDO, so don't pass to parent constructor, but assign directly.
// See https://github.com/amphp/parallel/issues/19.
$this->code = $code;
$this->name = $name;
$this->trace = $trace;
}