Skip to content

Commit

Permalink
Make Failure.mess robust when no message
Browse files Browse the repository at this point in the history
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 d499bd4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/Failure.pm6
Expand Up @@ -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:) {
Expand Down

4 comments on commit d499bd4

@MasterDuke17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jnthn
Copy link
Member Author

@jnthn jnthn commented on d499bd4 Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@lizmat
Copy link
Contributor

@lizmat lizmat commented on d499bd4 Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@MasterDuke17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.