Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept Throwable as rejection reason #31

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.2.2

### Fixed

- Fix accepting `Throwable` as rejection reason of a promise

## 1.2.1

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)

try {
return new self($onFulfilled($this->result));
} catch (\Exception $e) {
return new RejectedPromise($e);
} catch (\Throwable $exception) {
return new RejectedPromise($exception);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
final class RejectedPromise implements Promise
{
/**
* @var \Exception
* @var \Throwable
*/
private $exception;

public function __construct(\Exception $exception)
public function __construct(\Throwable $exception)
{
$this->exception = $exception;
}
Expand All @@ -34,8 +34,8 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)

try {
return new FulfilledPromise($onRejected($this->exception));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this moves the BC break from our own code to the callable. if the onRejected callback has a type declaration, the fatal error would now happen while calling the callback

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking, we're not breaking anything that wasn't broken before imho: if the callback did not accept a Throwable, then it keeps being broken, otherwise we were the ones that were broken, so it didn't matter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, correct. but thats why i wonder if we should do the widening or sharpen that a rejected promise can be about only a subset of exceptions.

} catch (\Exception $e) {
return new self($e);
} catch (\Throwable $exception) {
return new self($exception);
}
}

Expand Down
Loading