Fix error reporting, determine current template

hinted-selects
Vitaliy Filippov 2014-10-10 18:55:41 +04:00
parent 9de760790c
commit cdf833a277
5 changed files with 18 additions and 31 deletions

View File

@ -175,25 +175,6 @@ sub encode_mime_header($$;$) {
*Encode::MIME::Header::encode = *Bugzilla::encode_mime_header;
}
#####################################################################
# Another hack: install Template Toolkit error handler with stack traces
#####################################################################
sub _tt_exc_new
{
my ($class, $type, $info, $textref) = @_;
bless [ $type, $info, $textref, Devel::StackTrace->new->as_string ], $class;
}
sub _tt_exc_as_string
{
my $self = shift;
return $self->[0] . ' error - ' . $self->[1] . "\n" . $self->[3];
}
*Template::Exception::new = *Bugzilla::_tt_exc_new;
*Template::Exception::as_string = *Bugzilla::_tt_exc_as_string;
#####################################################################
# Hack for Template Toolkit (or maybe Perl) bug 67431
# https://rt.cpan.org/Public/Bug/Display.html?id=67431

View File

@ -286,8 +286,7 @@ sub ThrowCodeError
sub ThrowTemplateError
{
my ($template_err) = @_;
my ($msg, $stack) = split /\n{2,}/, "$template_err";
_throw_error('code', 'template_error', { template_error_msg => $msg, stack_trace => $stack });
_throw_error('code', 'template_error', { template_error_msg => $template_err->info, stack_trace => $template_err->[3] });
}
1;

View File

@ -526,6 +526,10 @@ sub get_bug_link
###############################################################################
# Templatization Code
use Template::Directive;
use Template::Stash;
use Template::Exception;
# The Template Toolkit throws an error if a loop iterates >1000 times.
# We want to raise that limit.
# NOTE: If you change this number, you MUST RE-RUN checksetup.pl!!!
@ -572,6 +576,16 @@ $Template::Stash::SCALAR_OPS->{truncate} = sub
return $newstr;
};
# Install Template Toolkit error handler with stack traces
*Template::Exception::new = sub
{
my ($class, $type, $info, $textref) = @_;
bless [
$type, $info, $textref,
$Bugzilla::Error::HAVE_DEVEL_STACKTRACE ? Devel::StackTrace->new->as_string : ''
], $class;
};
# Create the template object that processes templates and specify
# configuration parameters that apply to all templates.

View File

@ -29,6 +29,8 @@ use Scalar::Util qw(blessed);
sub process {
my $self = shift;
my ($template) = @_;
local $Bugzilla::Template::CURRENT_TEMPLATE = $template =~ /\.tmpl$/ ? $template : $Bugzilla::Template::CURRENT_TEMPLATE;
# We don't want to run the template_before_process hook for
# template hooks (but we do want it to run if a hook calls
# PROCESS inside itself). The problem is that the {component}->{name} of

View File

@ -46,16 +46,7 @@ sub process
if (!$template)
{
$template = $context->stash->get([ 'component', 0, 'name', 0 ]);
if ($template !~ /\.tmpl$/s)
{
my @callers = @{ $context->stash->get([ 'component', 0 ])->{callers} };
do
{
return '' if !@callers;
$template = pop @callers;
} while ($template !~ /\.tmpl$/s);
}
$template = $Bugzilla::Template::CURRENT_TEMPLATE;
}
# sanity check: