Commit 24f06218 authored by gerv%gerv.net's avatar gerv%gerv.net

Bug 162066 - Fix callers of ThrowCodeError to use messages in…

Bug 162066 - Fix callers of ThrowCodeError to use messages in code-error.html.tmpl. Patch by gerv; r=bbaetz.
parent 68424643
...@@ -218,11 +218,13 @@ sub CheckFormField (\%$;\@) { ...@@ -218,11 +218,13 @@ sub CheckFormField (\%$;\@) {
SendSQL("SELECT description FROM fielddefs WHERE name=" . SqlQuote($fieldname)); SendSQL("SELECT description FROM fielddefs WHERE name=" . SqlQuote($fieldname));
my $result = FetchOneColumn(); my $result = FetchOneColumn();
if ($result) { if ($result) {
ThrowCodeError("A legal $result was not set.", undef, "abort"); $vars->{'field'} = $result;
} }
else { else {
ThrowCodeError("A legal $fieldname was not set.", undef, "abort"); $vars->{'field'} = $fieldname;
} }
ThrowCodeError("illegal_field", "abort");
} }
} }
...@@ -233,9 +235,9 @@ sub CheckFormFieldDefined (\%$) { ...@@ -233,9 +235,9 @@ sub CheckFormFieldDefined (\%$) {
) = @_; ) = @_;
if (!defined $formRef->{$fieldname}) { if (!defined $formRef->{$fieldname}) {
ThrowCodeError("$fieldname was not defined; " . $vars->{'field'} = $fieldname;
Param("browserbugmessage")); ThrowCodeError("undefined_field");
} }
} }
sub BugAliasToID { sub BugAliasToID {
...@@ -876,7 +878,7 @@ sub DisplayError { ...@@ -876,7 +878,7 @@ sub DisplayError {
# For "this shouldn't happen"-type places in the code. # For "this shouldn't happen"-type places in the code.
# $vars->{'variables'} is a reference to a hash of useful debugging info. # $vars->{'variables'} is a reference to a hash of useful debugging info.
sub ThrowCodeError { sub ThrowCodeError {
($vars->{'error'}, $vars->{'variables'}, my $unlock_tables) = (@_); ($vars->{'error'}, my $unlock_tables, $vars->{'variables'}) = (@_);
SendSQL("UNLOCK TABLES") if $unlock_tables; SendSQL("UNLOCK TABLES") if $unlock_tables;
......
...@@ -251,15 +251,14 @@ foreach my $b (grep(/^bit-\d*$/, keys %::FORM)) { ...@@ -251,15 +251,14 @@ foreach my $b (grep(/^bit-\d*$/, keys %::FORM)) {
if ($::FORM{$b}) { if ($::FORM{$b}) {
my $v = substr($b, 4); my $v = substr($b, 4);
$v =~ /^(\d+)$/ $v =~ /^(\d+)$/
|| ThrowCodeError("One of the group bits submitted was invalid.", || ThrowCodeError("group_bit_invalid", "abort");
undef, "abort");
if (!GroupIsActive($v)) { if (!GroupIsActive($v)) {
# Prevent the user from adding the bug to an inactive group. # Prevent the user from adding the bug to an inactive group.
# Should only happen if there is a bug in Bugzilla or the user # Should only happen if there is a bug in Bugzilla or the user
# hacked the "enter bug" form since otherwise the UI # hacked the "enter bug" form since otherwise the UI
# for adding the bug to the group won't appear on that form. # for adding the bug to the group won't appear on that form.
ThrowCodeError("Attempted to add bug to an inactive group, " . $vars->{'bit'} = $v;
"identified by the bit '$v'.", undef, "abort"); ThrowCodeError("inactive_group", "abort");
} }
$sql .= " + $v"; # Carefully written so that the math is $sql .= " + $v"; # Carefully written so that the math is
# done by MySQL, which can handle 64-bit math, # done by MySQL, which can handle 64-bit math,
......
...@@ -805,9 +805,9 @@ SWITCH: for ($::FORM{'knob'}) { ...@@ -805,9 +805,9 @@ SWITCH: for ($::FORM{'knob'}) {
last SWITCH; last SWITCH;
}; };
# default
my $escaped_knob = html_quote($::FORM{'knob'}); $vars->{'action'} = $::FORM{'knob'};
ThrowCodeError("Unknown action $escaped_knob!\n"); ThrowCodeError("unknown_action");
} }
......
...@@ -42,13 +42,25 @@ ...@@ -42,13 +42,25 @@
to any [% parameters %] which you may have set before calling to any [% parameters %] which you may have set before calling
ThrowCodeError. ThrowCodeError.
[% ELSIF error == "another_error_tag" %] [% ELSIF error == "group_bit_invalid" %]
This is another sample error, without a special title. This One of the group bits submitted was invalid.
should be the usual usage for this file. This sample can be removed.
[% ELSIF error == "illegal_field" %]
A legal [% field FILTER html %] was not set.
[% ELSIF error == "inactive_group" %]
Attempted to add bug to an inactive group, identified by the bit
'[% bit FILTER html %]'.
[% ELSIF error == "template_error" %] [% ELSIF error == "template_error" %]
[% template_error_msg %] [% template_error_msg %]
[% ELSIF error == "undefined_field" %]
[% field FILTER html %] was not defined; [% Param('browserbugmessage') %]
[% ELSIF error == "unknown_action" %]
Unknown action [% action FILTER html %]!
[% ELSE %] [% ELSE %]
[%# Cope with legacy calling convention, where "error" was the string [%# Cope with legacy calling convention, where "error" was the string
# to print. # to print.
......
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