|
@@ -54,21 +54,23 @@ our $app = sub {
|
|
|
# Change your dir into whatever basedir you need to be in
|
|
# Change your dir into whatever basedir you need to be in
|
|
|
chdir("$options{tpsgi_dir}/$options{basedir}") or die "Can't chdir into $options{tpsgi_dir}/$options{'basedir'}: $!";
|
|
chdir("$options{tpsgi_dir}/$options{basedir}") or die "Can't chdir into $options{tpsgi_dir}/$options{'basedir'}: $!";
|
|
|
|
|
|
|
|
- # If we have manually set the NYTPROF var, use it and don't try to control
|
|
|
|
|
- # When to stop or start it.
|
|
|
|
|
- $ENV{NYTPROF} ||= "sigexit=1:savesrc=0:start=no:file=$options{tpsgi_dir}/prof/nytprof.out";
|
|
|
|
|
- require Devel::NYTProf;
|
|
|
|
|
- mkdir "$options{tpsgi_dir}/prof";
|
|
|
|
|
|
|
+ # Profiler is opt-in: set NYTPROF env var to enable.
|
|
|
|
|
+ # The default path is used when NYTPROF is set without a file= clause.
|
|
|
|
|
+ if ($ENV{NYTPROF}) {
|
|
|
|
|
+ $ENV{NYTPROF} = "sigexit=1:savesrc=0:start=no:file=$options{tpsgi_dir}/prof/nytprof.out"
|
|
|
|
|
+ unless $ENV{NYTPROF} =~ /file=/;
|
|
|
|
|
+ require Devel::NYTProf;
|
|
|
|
|
+ mkdir "$options{tpsgi_dir}/prof";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
my $self = TPSGI->new(%options);
|
|
my $self = TPSGI->new(%options);
|
|
|
- return eval { $self->app(@_) } || do {
|
|
|
|
|
- my $env = shift;
|
|
|
|
|
- $env->{'psgi.errors'}->print($@);
|
|
|
|
|
|
|
|
|
|
- # Redact the stack trace past line 1, it usually has things which should not be shown
|
|
|
|
|
- $self->{cur_query}->{message} = $@;
|
|
|
|
|
- $self->{cur_query}->{message} =~ s/\n.*//g if $self->{cur_query}->{message};
|
|
|
|
|
|
|
+ # TPSGI::app already catches all _app exceptions internally.
|
|
|
|
|
+ # This outer eval is a last-resort safety net only.
|
|
|
|
|
+ my $result = eval { $self->app(@_) };
|
|
|
|
|
+ return $result if defined $result;
|
|
|
|
|
|
|
|
- return $self->error($self->{cur_query});
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ my $env = $_[0];
|
|
|
|
|
+ $env->{'psgi.errors'}->print($@) if $env && ref $env eq 'HASH' && $env->{'psgi.errors'};
|
|
|
|
|
+ return [500, ['Content-Type', 'text/plain', 'Content-Length', 21], ['Internal Server Error']];
|
|
|
};
|
|
};
|