File tree 2 files changed +10
-3
lines changed
2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 1
1
package Mojo::Promise ;
2
2
use Mojo::Base -base;
3
3
4
- use Carp qw( carp) ;
4
+ use Carp qw( carp croak ) ;
5
5
use Mojo::Exception;
6
6
use Mojo::IOLoop;
7
7
use Scalar::Util qw( blessed) ;
@@ -18,8 +18,9 @@ sub AWAIT_FAIL { _settle_await(reject => @_) }
18
18
sub AWAIT_GET {
19
19
my $self = shift ;
20
20
my @results = @{$self -> {results } // []};
21
- die $results [0] unless $self -> {status } eq ' resolve' ;
22
- return wantarray ? @results : $results [0];
21
+ return wantarray ? @results : $results [0] if $self -> {status } eq ' resolve' ;
22
+ die $results [0] if ref $results [0] || $results [0] =~ m !\n ! ;
23
+ croak $results [0];
23
24
}
24
25
25
26
sub AWAIT_IS_CANCELLED {undef }
Original file line number Diff line number Diff line change @@ -137,6 +137,12 @@ subtest 'Exception handling and async/await' => sub {
137
137
$t -> get_ok(' /four' )-> status_is(500)-> content_like(qr / this went perfectly/ );
138
138
};
139
139
140
+ subtest ' Exception handling with file and line reporting' => sub {
141
+ my $error ;
142
+ reject_p()-> catch(sub { $error = shift })-> wait;
143
+ like $error , qr / ^Rejected promise at .*promise_async_await\. t line \d +\. $ / , ' right content' ;
144
+ };
145
+
140
146
subtest ' Exception handling without "Unhandled rejected promise" warning' => sub {
141
147
my ($error , @warn );
142
148
local $SIG {__WARN__ } = sub { push @warn , $_ [0] };
You can’t perform that action at this time.
0 commit comments