Bug 1263244 - Throw*Error inside templates should always use die(), as if…

Bug 1263244 - Throw*Error inside templates should always use die(), as if error_mode is ERROR_MODE_DIE r=dkl,a=dylan
parent af885190
...@@ -76,8 +76,6 @@ use constant SHUTDOWNHTML_RETRY_AFTER => 3600; ...@@ -76,8 +76,6 @@ use constant SHUTDOWNHTML_RETRY_AFTER => 3600;
# Global Code # Global Code
##################################################################### #####################################################################
#$::SIG{__DIE__} = i_am_cgi() ? \&CGI::Carp::confess : \&Carp::confess;
# Note that this is a raw subroutine, not a method, so $class isn't available. # Note that this is a raw subroutine, not a method, so $class isn't available.
sub init_page { sub init_page {
if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE) { if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE) {
......
...@@ -22,6 +22,7 @@ use Bugzilla::Hook; ...@@ -22,6 +22,7 @@ use Bugzilla::Hook;
use Carp; use Carp;
use Data::Dumper; use Data::Dumper;
use Date::Format; use Date::Format;
use Scalar::Util qw(blessed);
sub _throw_error { sub _throw_error {
my ($name, $error, $vars) = @_; my ($name, $error, $vars) = @_;
...@@ -68,7 +69,7 @@ sub _throw_error { ...@@ -68,7 +69,7 @@ sub _throw_error {
# There are some tests that throw and catch a lot of errors, # There are some tests that throw and catch a lot of errors,
# and calling $template->process over and over for those errors # and calling $template->process over and over for those errors
# is too slow. So instead, we just "die" with a dump of the arguments. # is too slow. So instead, we just "die" with a dump of the arguments.
if (Bugzilla->error_mode != ERROR_MODE_TEST) { if (Bugzilla->error_mode != ERROR_MODE_TEST && !$Bugzilla::Template::is_processing) {
$template->process($name, $vars, \$message) $template->process($name, $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
} }
...@@ -78,6 +79,12 @@ sub _throw_error { ...@@ -78,6 +79,12 @@ sub _throw_error {
Bugzilla::Hook::process('error_catch', { error => $error, vars => $vars, Bugzilla::Hook::process('error_catch', { error => $error, vars => $vars,
message => \$message }); message => \$message });
if ($Bugzilla::Template::is_processing) {
$name =~ /^global\/(user|code)-error/;
my $type = $1 // 'unknown';
die Template::Exception->new("bugzilla.$type.$error", $vars);
}
if (Bugzilla->error_mode == ERROR_MODE_WEBPAGE) { if (Bugzilla->error_mode == ERROR_MODE_WEBPAGE) {
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
$cgi->close_standby_message('text/html', 'inline', 'error', 'html'); $cgi->close_standby_message('text/html', 'inline', 'error', 'html');
...@@ -149,7 +156,7 @@ sub ThrowCodeError { ...@@ -149,7 +156,7 @@ sub ThrowCodeError {
# Don't show the error as coming from Bugzilla::Error, show it # Don't show the error as coming from Bugzilla::Error, show it
# as coming from the caller. # as coming from the caller.
local $Carp::CarpInternal{'Bugzilla::Error'} = 1; local $Carp::CarpInternal{'Bugzilla::Error'} = 1;
$vars->{traceback} = Carp::longmess(); $vars->{traceback} //= Carp::longmess();
_throw_error("global/code-error.html.tmpl", @_); _throw_error("global/code-error.html.tmpl", @_);
} }
...@@ -161,6 +168,14 @@ sub ThrowTemplateError { ...@@ -161,6 +168,14 @@ sub ThrowTemplateError {
# Make sure the transaction is rolled back (if supported). # Make sure the transaction is rolled back (if supported).
$dbh->bz_rollback_transaction() if $dbh->bz_in_transaction(); $dbh->bz_rollback_transaction() if $dbh->bz_in_transaction();
if (blessed($template_err) && $template_err->isa('Template::Exception')) {
my $type = $template_err->type;
if ($type =~ /^bugzilla\.(code|user)\.(.+)/) {
_throw_error("global/$1-error.html.tmpl", $2, $template_err->info);
return;
}
}
my $vars = {}; my $vars = {};
if (Bugzilla->error_mode == ERROR_MODE_DIE) { if (Bugzilla->error_mode == ERROR_MODE_DIE) {
die("error: template error: $template_err"); die("error: template error: $template_err");
......
...@@ -698,12 +698,15 @@ $Template::Stash::SCALAR_OPS->{ truncate } = ...@@ -698,12 +698,15 @@ $Template::Stash::SCALAR_OPS->{ truncate } =
############################################################################### ###############################################################################
our $is_processing = 0;
sub process { sub process {
my $self = shift; my $self = shift;
# All of this current_langs stuff allows template_inner to correctly # All of this current_langs stuff allows template_inner to correctly
# determine what-language Template object it should instantiate. # determine what-language Template object it should instantiate.
my $current_langs = Bugzilla->request_cache->{template_current_lang} ||= []; my $current_langs = Bugzilla->request_cache->{template_current_lang} ||= [];
unshift(@$current_langs, $self->context->{bz_language}); unshift(@$current_langs, $self->context->{bz_language});
local $is_processing = 1;
my $retval = $self->SUPER::process(@_); my $retval = $self->SUPER::process(@_);
shift @$current_langs; shift @$current_langs;
return $retval; return $retval;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment