Skip to content

Commit

Permalink
Initial support for error reporting plugins
Browse files Browse the repository at this point in the history
This attempts to address RT #128983 .  Whenever an error is to be
reported, the RAKUDO_EXCEPTIONS_HANDLER environment variable is
checked: if it contains something, it is considered to be the name
of a class extending the Exceptions:: class (so "JSON" would refer
to the Exceptions::JSON class).  If such a class exists, then the
method "process" is called in that class, with the Exception object
as the parameter.  That method is than supposed to completely handle
the error reporting.

This patch also adds an Exceptions::JSON class that outputs the
exception information as JSON on STDERR.
  • Loading branch information
lizmat committed Aug 23, 2016
1 parent 2181f7e commit aaf7c3c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/Exception.pm
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ do {

sub print_exception(|) {
my Mu $ex := nqp::atpos(nqp::p6argvmarray(), 0);

if %*ENV<RAKUDO_EXCEPTIONS_HANDLER> -> $handler {
my $class := ::("Exceptions::$handler");
unless nqp::istype($class,Failure) {
temp %*ENV<RAKUDO_EXCEPTIONS_HANDLER> = ""; # prevent looping
return $class.process(EXCEPTION($ex))
}
}

try {
my $e := EXCEPTION($ex);
my $v := $e.vault-backtrace;
Expand Down Expand Up @@ -2577,4 +2586,18 @@ my class X::CompUnit::UnsatisfiedDependency is Exception {
}
}

my class Exceptions::JSON {
method process($ex) {
nqp::printfh(
nqp::getstderr,
Rakudo::Internals::JSON.to-json( $ex.^name => Hash.new(
(message => $ex.message),
$ex.^attributes.grep(*.has_accessor).map: {
$_ => $ex."$_"() with .name.substr(2)
}
))
)
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit aaf7c3c

Please sign in to comment.