Mojo::Promise swallows exceptions in rejection handlers

52 views
Skip to first unread message

Rob Foehl

unread,
Nov 16, 2017, 2:23:27 AM11/16/17
to mojol...@googlegroups.com
Just ran into this on 7.55:

╶➤ perl -MMojo::Promise -le 'my $p = Mojo::Promise->new; $p->reject("die, please"); $p->catch(sub { die "oops: $_[0]\n" }); $p->wait'

Silence... Change the die to a warn, and:

╶➤ perl -MMojo::Promise -le 'my $p = Mojo::Promise->new; $p->reject("die, please"); $p->catch(sub { warn "oops: $_[0]\n" }); $p->wait'
oops: die, please

The promise is correctly rejected (confirmed by poking at $p->{status}),
but the exception disappears. I'm guessing that wasn't the intent, but
I'm not entirely sure after a brief glance at the implementation...

-Rob

Dan Book

unread,
Nov 16, 2017, 2:33:48 AM11/16/17
to mojol...@googlegroups.com
The problem is that no exceptions in promise handlers are fatal, they occur in the event loop. The only way the exception could be propagated is if the call to ->wait checked for a failure and rethrew it as an exception afterward (this is how ->get works in Future). Also note that $p is not the last promise in the chain, that is returned by the ->catch call (so you would normally chain ->wait after that). I'm not sure what the idiomatic way is to accomplish this with promises.

-Dan



-Rob

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscribe@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

sri

unread,
Nov 16, 2017, 5:40:16 AM11/16/17
to Mojolicious
I'm guessing that wasn't the intent, but 
I'm not entirely sure after a brief glance at the implementation...

It is intended, of course we welcome ideas for making
Mojo::Promise more dwim, as long as it doesn't conflict with the
specs.

--
sebastian
Reply all
Reply to author
Forward
0 new messages