Skip to content

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

@kelunik

Description

@kelunik

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;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions