summaryrefslogtreecommitdiffstats
path: root/CGI.pl
diff options
context:
space:
mode:
authorbbaetz%acm.org <>2003-09-14 15:04:38 +0200
committerbbaetz%acm.org <>2003-09-14 15:04:38 +0200
commit4e7e3310242bd5264b5f48e4bf3c387e59288b85 (patch)
treedf9878685199a51358c148c1531d51116f32f650 /CGI.pl
parent95791d4b9edc26cd55483e71970d9f743f12f094 (diff)
downloadbugzilla-4e7e3310242bd5264b5f48e4bf3c387e59288b85.tar.gz
bugzilla-4e7e3310242bd5264b5f48e4bf3c387e59288b85.tar.xz
Bug 208699 - Move Throw{Code,Template}Error into Error.pm
r,a=justdave
Diffstat (limited to 'CGI.pl')
-rw-r--r--CGI.pl85
1 files changed, 5 insertions, 80 deletions
diff --git a/CGI.pl b/CGI.pl
index 8b33ce102..75174dcba 100644
--- a/CGI.pl
+++ b/CGI.pl
@@ -95,14 +95,15 @@ sub CheckFormField (\%$;\@) {
SendSQL("SELECT description FROM fielddefs WHERE name=" . SqlQuote($fieldname));
my $result = FetchOneColumn();
+ my $field;
if ($result) {
- $vars->{'field'} = $result;
+ $field = $result;
}
else {
- $vars->{'field'} = $fieldname;
+ $field = $fieldname;
}
- ThrowCodeError("illegal_field", undef, "abort");
+ ThrowCodeError("illegal_field", { field => $field }, "abort");
}
}
@@ -113,8 +114,7 @@ sub CheckFormFieldDefined (\%$) {
) = @_;
if (!defined $formRef->{$fieldname}) {
- $vars->{'field'} = $fieldname;
- ThrowCodeError("undefined_field");
+ ThrowCodeError("undefined_field", { field => $fieldname });
}
}
@@ -241,81 +241,6 @@ sub PutFooter {
|| ThrowTemplateError($::template->error());
}
-###############################################################################
-# Error handling
-#
-# If you are doing incremental output, set $vars->{'header_done'} once you've
-# done the header.
-#
-# You can call Throw*Error with extra template variables in one pass by using
-# the $extra_vars hash reference parameter:
-# ThrowUserError("some_tag", { bug_id => $bug_id, size => 127 });
-###############################################################################
-
-# For "this shouldn't happen"-type places in the code.
-# The contents of $extra_vars get printed out in the template - useful for
-# debugging info.
-sub ThrowCodeError {
- ($vars->{'error'}, my $extra_vars, my $unlock_tables) = (@_);
-
- SendSQL("UNLOCK TABLES") if $unlock_tables;
-
- # If we don't have this test here, then the %@extra_vars vivifies
- # the hashref, and then setting $vars->{'variables'} uses an empty hashref
- # so the error template prints out a bogus header for the empty hash
- if (defined $extra_vars) {
- # Copy the extra_vars into the vars hash
- foreach my $var (keys %$extra_vars) {
- $vars->{$var} = $extra_vars->{$var};
- }
-
- # We may one day log something to file here also.
- $vars->{'variables'} = $extra_vars;
- }
-
- print Bugzilla->cgi->header();
- $template->process("global/code-error.html.tmpl", $vars)
- || ThrowTemplateError($template->error());
-
- exit;
-}
-
-# This function should only be called if a template->process() fails.
-# It tries another template first, because often one template being
-# broken or missing doesn't mean that they all are. But it falls back on
-# a print statement.
-# The Content-Type will already have been printed.
-sub ThrowTemplateError {
- ($vars->{'template_error_msg'}) = (@_);
- $vars->{'error'} = "template_error";
-
- # Try a template first; but if this one fails too, fall back
- # on plain old print statements.
- if (!$template->process("global/code-error.html.tmpl", $vars)) {
- my $maintainer = Param('maintainer');
- my $error = html_quote($vars->{'template_error_msg'});
- my $error2 = html_quote($template->error());
- print <<END;
- <tt>
- <p>
- Bugzilla has suffered an internal error. Please save this page and
- send it to $maintainer with details of what you were doing at the
- time this message appeared.
- </p>
- <script type="text/javascript"> <!--
- document.write("<p>URL: " + document.location + "</p>");
- // -->
- </script>
- <p>Template->process() failed twice.<br>
- First error: $error<br>
- Second error: $error2</p>
- </tt>
-END
- }
-
- exit;
-}
-
sub CheckIfVotedConfirmed {
my ($id, $who) = (@_);
SendSQL("SELECT bugs.votes, bugs.bug_status, products.votestoconfirm, " .