Skip to content
Permalink
Browse files

Make Failure.mess robust when no message

Previously, if the exception lacked a `message` method, then it would
blow up with a method not found error when trying to display the
Failure. Since this can happen via DESTROY for an unhandled Failure,
this could happen at pretty much any point in the program. Make it
robust in the face of a missing `message` method in the exception.
Resolves #2623.
  • Loading branch information...
jnthn committed Jan 25, 2019
1 parent 4fd8e87 commit d499bd4bc8e333e7c3c54a0c434113fa7b6a763e
Showing with 2 additions and 1 deletion.
  1. +2 −1 src/core/Failure.pm6
@@ -91,7 +91,8 @@ my class Failure is Nil {
}
multi method perl(Failure:U:) { self.^name }
method mess (Failure:D:) {
"(HANDLED) " x $!handled ~ self.exception.message ~ "\n" ~ self.backtrace;
my $message = (try self.exception.?message) // self.exception.^name ~ ' with no message';
"(HANDLED) " x $!handled ~ "$message\n" ~ self.backtrace;
}

method sink(Failure:D:) {

4 comments on commit d499bd4

@MasterDuke17

This comment has been minimized.

Copy link
Contributor

replied Jan 25, 2019

OOC, why is it (try self.exception.?message) instead of just self.exception.?message?

@jnthn

This comment has been minimized.

Copy link
Member Author

replied Jan 25, 2019

In case there is a message but it crashes; I followed the same thing that happens in Exception.gist.

@lizmat

This comment has been minimized.

Copy link
Contributor

replied Jan 25, 2019

Oddly enough I was looking at that same line of code yesterday :-)

@MasterDuke17

This comment has been minimized.

Copy link
Contributor

replied Jan 25, 2019

Heh, now that you mention it I even wrote some of those try lines in Exception.gist. If only I'd remembered that before asking the question...

Please sign in to comment.
You can’t perform that action at this time.