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

done() exceptions bubble up into the wrong place #88

Closed
kelunik opened this issue Feb 20, 2017 · 0 comments · Fixed by #97
Closed

done() exceptions bubble up into the wrong place #88

kelunik opened this issue Feb 20, 2017 · 0 comments · Fixed by #97

Comments

@kelunik
Copy link

kelunik commented Feb 20, 2017

done() callbacks aren't supposed to throw exceptions, but they might, because bugs. If this happens, the exception just bubbles up into the reject() call where it shouldn't end up, because reject() isn't supposed to throw exceptions. The resolution and consumption parts should be strictly separated and not affect each other. One solution is to use trigger_error($exception, E_USER_ERROR); instead.

Additionally, an error handler could be used similar to the one proposed in async-interop to allow users to catch and log these errors but continue execution.

The following code snippet demonstrates reject() throwing while it's not supposed to throw.

<?php

require __DIR__ . "/vendor/autoload.php";

$deferred = new React\Promise\Deferred;

$deferred->promise()->done(function ($value) { }, function ($reason) {
    throw new Exception;
});

try {
    $deferred->reject("foobar");
} catch (Exception $e) {
    print "Uhm... reject isn't supposed to throw." . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants