|
NAMECatalyst::Plugin::ErrorCatcher - Catch application errors and emit them somewhere VERSIONversion 0.0.8.21 SYNOPSISuse Catalyst qw/-Debug StackTrace ErrorCatcher/; DESCRIPTIONThis plugin allows you to do More Stuff with the information that would normally only be seen on the Catalyst Error Screen courtesy of the Catalyst::Plugin::StackTrace plugin. setup($c, $@)Prepare the plugin for use. finalize_error($c)If configured, and needed, deal with raised errors. my_finalize_error($c)This is the method that's called by "finalize_error" when we do want to use ErrorCatcher to format and emit some information. emitters_init($c)This routine initialises the emitters enabled in the configuration for the plugin. append_feedback($stringref, $data)This is a small utility method that simplifies some of the work needed to add some data to a string-reference, including some basic checks and initialisation. append_feedback_emptylineAdd an empty-line to the string-reference of data being built. append_feedback_keyvalue($ref, $key, $value, $keypadding)Add: {key}: value
to the feedback data being prepared. $keypadding is optional. If omitted, defaults to 8. sanitise_param($value)Local implementation of "qquote" in Data::Dumper and general sanity checks and transformations of the data in a given piece of data. append_output_params($ref, $label, $params)Given a hashref of related items, $params, and a $label for the grouping, add sensibly formatted output to the feedback data being constructed. CONFIGURATIONThe plugin is configured in a similar manner to other Catalyst plugins: <Plugin::ErrorCatcher>
enable 1
context 5
always_log 0
include_session 0
user_identified_by username
emit_module A::Module
</Plugin::ErrorCatcher>
STACKTRACE IN REPORTS WHEN NOT RUNNING IN DEBUG MODEIt is possible to run your application in non-Debug mode, and still have errors reported with a stack-trace. Include the StackTrace and ErrorCatcher plugins in MyApp.pm: use Catalyst qw<
ErrorCatcher
StackTrace
>;
Set up your "myapp.conf" to include the following: <stacktrace>
enable 1
</stacktrace>
<Plugin::ErrorCatcher>
enable 1
# include other options here
<Plugin::ErrorCatcher>
Any exceptions should now show your user the "Please come back later" screen whilst still capturing and emitting a report with stack-trace. PROVIDED EMIT CLASSESCatalyst::Plugin::ErrorCatcher::EmailThis module uses MIME::Lite to send the prepared output to a specified email address. See Catalyst::Plugin::ErrorCatcher::Email for usage and configuration details. CUSTOM EMIT CLASSESA custom emit class takes the following format: package A::Module;
# vim: ts=8 sts=4 et sw=4 sr sta
use strict;
use warnings;
sub emit {
my ($class, $c, $output) = @_;
$c->log->info(
'IGNORING OUTPUT FROM Catalyst::Plugin::ErrorCatcher'
);
return;
}
1;
__END__
The only requirement is that you have a sub called "emit". "Catalyst::Plugin::ErrorCatcher" passes the following parameters in the call to emit():
If you want to use the original error message you should use: my @error = @{ $c->error };
You may use and abuse any Catalyst methods, or other Perl modules as you see fit. KNOWN ISSUES
SEE ALSOCatalyst, Catalyst::Plugin::StackTrace THANKSThe authors of Catalyst::Plugin::StackTrace, from which a lot of code was used. Ash Berlin for guiding me in the right direction after a known hacky first implementation. # vim: ts=8 sts=4 et sw=4 sr sta AUTHORChisel <chisel@chizography.net> COPYRIGHT AND LICENSEThis software is copyright (c) 2015 by Chisel Wright. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. CONTRIBUTORS
|