-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Add new set_rejection_handler()
function for unhandled rejections
#249
Conversation
set_rejection_handler()
functionset_rejection_handler()
function for unhandled rejections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
public function __destruct() | ||
{ | ||
if ($this->handled) { | ||
return; | ||
} | ||
|
||
$message = 'Unhandled promise rejection with ' . \get_class($this->reason) . ': ' . $this->reason->getMessage() . ' in ' . $this->reason->getFile() . ':' . $this->reason->getLine() . PHP_EOL; | ||
$message .= 'Stack trace:' . PHP_EOL . $this->reason->getTraceAsString(); | ||
$handler = set_rejection_handler(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello.
Why did you make this handler one-time use? In this case, it's hard to even guess on which promise it will be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, it's one time use because this is inside the promise that is not handled when rejected. It will only ever run once. It might run again for another promise, but not this specific one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there is no connection between the handler and the promise here. I can't explicitly specify which promise this handler is for. And if the user completes another promise without handling the exception, they will not be notified about it, while the promise for which I would like to define a handler will complete without a handler.
Are you considering the possibility of adding a function to set a global persistent handler for all promises? Or add the ability to specify a chain of promises for the handler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @roxblnfk, took a closer look at this with @clue and it seems like following exceptions are currently not being handled correctly. We'll look into this, create some additional tests for multiple exceptions to define our expected behavior and implement a fix.
Thanks for taking the time and bringing this up 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think I misunderstood your initial comment. You are right, this shouldn't be a one use only handler but a persistent one instead. We're looking into adding additional tests and a fix for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
This changeset adds a new
set_rejection_handler()
function to set the global rejection handler for unhandled promise rejections.The default promise rejection handler will log an error message plus its stack trace. The new
set_rejection_handler()
function may be used to use customize the log message or write to custom log targets.Builds on top of #248
Refs #87