Closed nabertrand closed 6 months ago
Any die
inside of a then()
or catch()
callback is caught by the promise and bubbled to the next catch
handler in the chain. Unhandled rejections at the end of the chain are caught by the promise and reported via warn()
, but I didn't intend for any to get this far. In any case, I haven't seen LMS keel over yet!
That said, a review of error handling with the promises is on my to-do list because I wouldn't be surprised if I missed something or if it's swallowing something that should be reported or if some errors are reported in a confusing way.
Nice, thanks for explaining. I'd never seen Promise::ES6 before, so I'm still trying to wrap my head around it all. It does seem to simplify having to pass around callbacks.
If you're new to promises, https://metacpan.org/dist/Promises/view/lib/Promises/Cookbook/GentleIntro.pod provides a good overview, albeit slightly specific to the Promises module. I chose Promises::ES6 because it had no dependencies, but the promise pattern is the same.
Having worked with javascript, I really wanted to try promises in this plugin as a way to manage the callbacks. Let me know what you think.
Does calling
die
cause LMS to exit or are these calls caught somewhere?https://github.com/sspiff/lms-plugin-pyrrha/blob/9e5da3e849223328ad0e1701aef37845f0866432/plugin/ProtocolHandler.pm#L81