Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ function ($error) use (&$exception, &$rejected, &$wait, $loop) {
}

if ($rejected) {
if (!$exception instanceof \Exception) {
$exception = new \UnexpectedValueException(
'Promise rejected with unexpected value of type ' . (is_object($exception) ? get_class($exception) : gettype($exception)),
0,
$exception instanceof \Throwable ? $exception : null
);
if ($exception instanceof \Throwable || $exception instanceof \Exception) {
throw $exception;
}

throw $exception;
throw new \UnexpectedValueException(
'Promise rejected with unexpected value of type '
. (is_object($exception)
? get_class($exception)
: gettype($exception))
);
}

return $resolved;
Expand Down
8 changes: 3 additions & 5 deletions tests/FunctionAwaitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ public function testAwaitOneRejectedWithNullWillWrapInUnexpectedValueException()
/**
* @requires PHP 7
*/
public function testAwaitOneRejectedWithPhp7ErrorWillWrapInUnexpectedValueExceptionWithPrevious()
public function testAwaitOneRejectedWithPhp7ErrorWillThrowThatVerySameError()
{
$promise = Promise\reject(new \Error('Test'));

try {
Block\await($promise, $this->loop);
$this->fail();
} catch (\UnexpectedValueException $e) {
$this->assertEquals('Promise rejected with unexpected value of type Error', $e->getMessage());
$this->assertInstanceOf('Throwable', $e->getPrevious());
$this->assertEquals('Test', $e->getPrevious()->getMessage());
} catch (\Error $e) {
$this->assertEquals('Test', $e->getMessage());
}
}

Expand Down