mirror of
https://github.com/amphp/parallel.git
synced 2025-02-21 13:22:44 +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:
parent
0e71b18197
commit
26e826a05f
@ -14,15 +14,11 @@ class PanicError extends \Error {
|
|||||||
*
|
*
|
||||||
* @param string $name The uncaught exception class.
|
* @param string $name The uncaught exception class.
|
||||||
* @param string $message The panic message.
|
* @param string $message The panic message.
|
||||||
* @param mixed $code The panic code.
|
|
||||||
* @param string $trace The panic stack trace.
|
* @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);
|
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->name = $name;
|
||||||
$this->trace = $trace;
|
$this->trace = $trace;
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ interface Channel {
|
|||||||
* @throws \Amp\Parallel\StatusError Thrown if the context has not been started.
|
* @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
|
* @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context
|
||||||
* unexpectedly ends.
|
* unexpectedly ends.
|
||||||
* @throws \Amp\Parallel\ChannelException If receiving from the channel fails.
|
* @throws \Amp\Parallel\Sync\ChannelException If receiving from the channel fails.
|
||||||
* @throws \Amp\Parallel\SerializationException If unserializing the data fails.
|
* @throws \Amp\Parallel\Sync\SerializationException If unserializing the data fails.
|
||||||
*/
|
*/
|
||||||
public function receive(): Promise;
|
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\StatusError Thrown if the context has not been started.
|
||||||
* @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context
|
* @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context
|
||||||
* unexpectedly ends.
|
* 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 \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;
|
public function send($data): Promise;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class ExitFailure implements ExitResult {
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private $message;
|
private $message;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int|string */
|
||||||
private $code;
|
private $code;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
@ -31,11 +31,11 @@ class ExitFailure implements ExitResult {
|
|||||||
throw new PanicError(
|
throw new PanicError(
|
||||||
$this->type,
|
$this->type,
|
||||||
\sprintf(
|
\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->type,
|
||||||
$this->message
|
$this->message,
|
||||||
|
$this->code
|
||||||
),
|
),
|
||||||
$this->code,
|
|
||||||
$this->trace
|
$this->trace
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class TaskFailure extends TaskResult {
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private $message;
|
private $message;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int|string */
|
||||||
private $code;
|
private $code;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
@ -41,8 +41,12 @@ class TaskFailure extends TaskResult {
|
|||||||
case self::PARENT_ERROR:
|
case self::PARENT_ERROR:
|
||||||
$exception = new TaskError(
|
$exception = new TaskError(
|
||||||
$this->type,
|
$this->type,
|
||||||
sprintf('Uncaught Error in worker of type "%s" with message "%s"', $this->type, $this->message),
|
sprintf(
|
||||||
$this->code,
|
'Uncaught Error in worker of type "%s" with message "%s" and code "%s"',
|
||||||
|
$this->type,
|
||||||
|
$this->message,
|
||||||
|
$this->code
|
||||||
|
),
|
||||||
$this->trace
|
$this->trace
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -50,8 +54,12 @@ class TaskFailure extends TaskResult {
|
|||||||
default:
|
default:
|
||||||
$exception = new TaskException(
|
$exception = new TaskException(
|
||||||
$this->type,
|
$this->type,
|
||||||
sprintf('Uncaught Exception in worker of type "%s" with message "%s"', $this->type, $this->message),
|
sprintf(
|
||||||
$this->code,
|
'Uncaught Exception in worker of type "%s" with message "%s" and code "%s"',
|
||||||
|
$this->type,
|
||||||
|
$this->message,
|
||||||
|
$this->code
|
||||||
|
),
|
||||||
$this->trace
|
$this->trace
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,11 @@ class TaskError extends \Error {
|
|||||||
/**
|
/**
|
||||||
* @param string $name The exception class name.
|
* @param string $name The exception class name.
|
||||||
* @param string $message The panic message.
|
* @param string $message The panic message.
|
||||||
* @param mixed $code The panic code.
|
|
||||||
* @param string $trace The panic stack trace.
|
* @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);
|
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->name = $name;
|
||||||
$this->trace = $trace;
|
$this->trace = $trace;
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,11 @@ class TaskException extends \Exception {
|
|||||||
/**
|
/**
|
||||||
* @param string $name The exception class name.
|
* @param string $name The exception class name.
|
||||||
* @param string $message The panic message.
|
* @param string $message The panic message.
|
||||||
* @param mixed $code The panic code.
|
|
||||||
* @param string $trace The panic stack trace.
|
* @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);
|
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->name = $name;
|
||||||
$this->trace = $trace;
|
$this->trace = $trace;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user