summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-10-22 17:24:03 +0200
committerYorhel <git@yorhel.nl>2008-10-22 17:24:03 +0200
commitb887cbb0a294bf806ef0c031342d74404abb2582 (patch)
tree5fd4273845422d4aaa634512929998cb84ede052
parent6cce43e53da9a43bfca7c1f37f7d53936e130da0 (diff)
Improved error reporting
This is going to make debugging a lot easier
-rw-r--r--lib/VNDB/Handler/Example.pm12
-rw-r--r--lib/YAWF.pm19
2 files changed, 28 insertions, 3 deletions
diff --git a/lib/VNDB/Handler/Example.pm b/lib/VNDB/Handler/Example.pm
index 36e419f..6d18422 100644
--- a/lib/VNDB/Handler/Example.pm
+++ b/lib/VNDB/Handler/Example.pm
@@ -7,7 +7,8 @@ use YAWF;
YAWF::register(
- qr/envdump/, \&envdump
+ qr/envdump/, \&envdump,
+ qr/error/, \&error,
);
@@ -33,5 +34,14 @@ sub envdump {
}
+sub error {
+ # this handler demonstrates a function that fails, YAWF
+ # should display a 500 error page and write a detailed
+ # report to the log file
+ warn "A random warning message before the error actually occurs";
+ die "Some descriptive error message here";
+}
+
+
1;
diff --git a/lib/YAWF.pm b/lib/YAWF.pm
index 7d0fcc5..ae29dee 100644
--- a/lib/YAWF.pm
+++ b/lib/YAWF.pm
@@ -73,7 +73,7 @@ sub register {
# Writes warning messages to the log file (if there is a log file)
sub log_warning {
- if($YAWF::OBJ->{_YAWF}{logfile} && open my $F, '>>', $YAWF::OBJ->{_YAWF}{logfile}) {
+ if($YAWF::OBJ->{_YAWF}{logfile} && open my $F, '>>:utf8', $YAWF::OBJ->{_YAWF}{logfile}) {
flock $F, 2;
seek $F, 0, 2;
while(local $_ = shift) {
@@ -164,6 +164,8 @@ sub handle_request {
# error handling
if($@) {
+ chomp( my $err = $@ );
+
# act as if the changes to the DB never happened
eval { $self->dbRollBack; };
warn $@ if $@;
@@ -180,7 +182,20 @@ sub handle_request {
YAWF::DefaultHandlers::error_500($self);
}
- # some logging here...
+ # write detailed information about this error to the log
+ if($self->{_YAWF}{logfile} && open my $F, '>>:utf8', $self->{_YAWF}{logfile}) {
+ flock $F, 2;
+ seek $F, 0, 2;
+ printf $F "[%s] %s: FATAL ERROR!\n", scalar localtime(), $self->reqURI||'[init]';
+ print $F "HTTP Request Headers:\n";
+ printf $F " %s: %s\n", $_, $self->reqHeader($_) for ($self->reqHeader);
+ print $F "Param dump:\n";
+ printf $F " %s: %s\n", $_, $self->reqParam($_) for ($self->reqParam);
+ print $F "Error:\n";
+ printf $F " %s\n", $err;
+ flock $F, 4;
+ close $F;
+ }
}
# finalize response (flush output, etc)