Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix 'fail' so it also prints a backtrace
This works in all cases except when the fail is the last statement of
our program. The call to .sink in main.nqp seems to introduce a problem,
which results in a low level backtrace that does not even show the file
and line number of the user's code.
  • Loading branch information
FROGGS committed Jun 28, 2014
1 parent dd1a437 commit 6be4d2b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/core/Failure.pm
Expand Up @@ -35,14 +35,30 @@ my class Failure {
$!exception.throw;
}
);
method sink() { $!exception.throw unless $!handled }
method sink() is hidden_from_backtrace {
$!exception.throw unless $!handled
}
}

my &fail := -> *@msg {
my $value = @msg == 1 ?? @msg[0] !! @msg.join('');
die $value if $*FATAL;
try die $value;
my $fail := Failure.new($!);
proto sub fail(|) is hidden_from_backtrace {*};
multi sub fail(Exception $e) is hidden_from_backtrace {
die $e if $*FATAL;
my $fail := Failure.new($e);
my Mu $return := nqp::getlexcaller('RETURN');
$return($fail) unless nqp::isnull($return);
$fail
}
multi sub fail($payload) is hidden_from_backtrace {
die $payload if $*FATAL;
my $fail := Failure.new(X::AdHoc.new(:$payload));
my Mu $return := nqp::getlexcaller('RETURN');
$return($fail) unless nqp::isnull($return);
$fail
}
multi sub fail(*@msg) is hidden_from_backtrace {
my $payload = @msg == 1 ?? @msg[0] !! @msg.join('');
die $payload if $*FATAL;
my $fail := Failure.new(X::AdHoc.new(:$payload));
my Mu $return := nqp::getlexcaller('RETURN');
$return($fail) unless nqp::isnull($return);
$fail
Expand Down

0 comments on commit 6be4d2b

Please sign in to comment.