Commit 2a6f7d46 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 676844: Replace ThrowCodeError() by ThrowUserError() when the error is not…

Bug 676844: Replace ThrowCodeError() by ThrowUserError() when the error is not triggered by the code itself r=glob a=LpSolit
parent 34a9d58c
......@@ -756,7 +756,7 @@ sub validate_obsolete {
$vars->{'attach_id'} = $attachid;
detaint_natural($attachid)
|| ThrowCodeError('invalid_attach_id_to_obsolete', $vars);
|| ThrowUserError('invalid_attach_id', $vars);
# Make sure the attachment exists in the database.
my $attachment = new Bugzilla::Attachment($attachid)
......@@ -771,7 +771,7 @@ sub validate_obsolete {
if ($attachment->bug_id != $bug->bug_id) {
$vars->{'my_bug_id'} = $bug->bug_id;
$vars->{'attach_bug_id'} = $attachment->bug_id;
ThrowCodeError('mismatched_bug_ids_on_obsolete', $vars);
ThrowUserError('mismatched_bug_ids_on_obsolete', $vars);
}
next if $attachment->isobsolete;
......@@ -879,7 +879,7 @@ sub run_create_validators {
$params->{creation_ts} ||= Bugzilla->dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');
$params->{modification_time} = $params->{creation_ts};
$params->{submitter_id} = Bugzilla->user->id || ThrowCodeError('invalid_user');
$params->{submitter_id} = Bugzilla->user->id || ThrowUserError('invalid_user');
return $params;
}
......@@ -962,10 +962,18 @@ sub get_content_type {
return 'text/plain' if ($cgi->param('ispatch') || $cgi->param('attach_text'));
my $content_type;
if (!defined $cgi->param('contenttypemethod')) {
ThrowUserError("missing_content_type_method");
my $method = $cgi->param('contenttypemethod') || '';
if ($method eq 'list') {
# The user selected a content type from the list, so use their
# selection.
$content_type = $cgi->param('contenttypeselection');
}
elsif ($cgi->param('contenttypemethod') eq 'autodetect') {
elsif ($method eq 'manual') {
# The user entered a content type manually, so use their entry.
$content_type = $cgi->param('contenttypeentry');
}
else {
defined $cgi->upload('data') || ThrowUserError('file_not_specified');
# The user asked us to auto-detect the content type, so use the type
# specified in the HTTP request headers.
......@@ -979,19 +987,6 @@ sub get_content_type {
$content_type = 'image/png';
}
}
elsif ($cgi->param('contenttypemethod') eq 'list') {
# The user selected a content type from the list, so use their
# selection.
$content_type = $cgi->param('contenttypeselection');
}
elsif ($cgi->param('contenttypemethod') eq 'manual') {
# The user entered a content type manually, so use their entry.
$content_type = $cgi->param('contenttypeentry');
}
else {
ThrowCodeError("illegal_content_type_method",
{ contenttypemethod => $cgi->param('contenttypemethod') });
}
return $content_type;
}
......
......@@ -665,7 +665,7 @@ sub _check_requestee {
# is specifically requestable. For existing flags, if the requestee
# was set before the flag became specifically unrequestable, the
# user can either remove him or leave him alone.
ThrowCodeError('flag_requestee_disabled', { type => $self->type })
ThrowUserError('flag_requestee_disabled', { type => $self->type })
if !$self->type->is_requesteeble;
# Make sure the requestee can see the bug.
......@@ -719,7 +719,7 @@ sub _check_setter {
# By default, the currently logged in user is the setter.
$setter ||= Bugzilla->user;
(blessed($setter) && $setter->isa('Bugzilla::User') && $setter->id)
|| ThrowCodeError('invalid_user');
|| ThrowUserError('invalid_user');
# set_status() has already been called. So this refers
# to the new flag status.
......
......@@ -40,7 +40,7 @@ sub new {
my $class = shift;
if (!Bugzilla->feature('jobqueue')) {
ThrowCodeError('feature_disabled', { feature => 'jobqueue' });
ThrowUserError('feature_disabled', { feature => 'jobqueue' });
}
my $lc = Bugzilla->localconfig;
......
......@@ -741,7 +741,7 @@ sub detect_encoding {
my $data = shift;
Bugzilla->feature('detect_charset')
|| ThrowCodeError('feature_disabled', { feature => 'detect_charset' });
|| ThrowUserError('feature_disabled', { feature => 'detect_charset' });
require Encode::Detect::Detector;
import Encode::Detect::Detector 'detect';
......
......@@ -52,7 +52,7 @@ my $dbh = Bugzilla->dbh;
my $user = Bugzilla->login(LOGIN_REQUIRED);
if (!Bugzilla->feature('new_charts')) {
ThrowCodeError('feature_disabled', { feature => 'new_charts' });
ThrowUserError('feature_disabled', { feature => 'new_charts' });
}
# Go back to query.cgi if we are adding a boolean chart parameter.
......@@ -269,12 +269,12 @@ sub validateWidthAndHeight {
if (defined($vars->{'width'})) {
(detaint_natural($vars->{'width'}) && $vars->{'width'} > 0)
|| ThrowCodeError("invalid_dimensions");
|| ThrowUserError("invalid_dimensions");
}
if (defined($vars->{'height'})) {
(detaint_natural($vars->{'height'}) && $vars->{'height'} > 0)
|| ThrowCodeError("invalid_dimensions");
|| ThrowUserError("invalid_dimensions");
}
# The equivalent of 2000 square seems like a very reasonable maximum size.
......
......@@ -97,7 +97,7 @@ if ($action eq 'new') {
if ($action eq 'edit') {
my $keyword = new Bugzilla::Keyword($key_id)
|| ThrowCodeError('invalid_keyword_id', { id => $key_id });
|| ThrowUserError('invalid_keyword_id', { id => $key_id });
$vars->{'keyword'} = $keyword;
$vars->{'token'} = issue_session_token('edit_keyword');
......@@ -116,7 +116,7 @@ if ($action eq 'edit') {
if ($action eq 'update') {
check_token_data($token, 'edit_keyword');
my $keyword = new Bugzilla::Keyword($key_id)
|| ThrowCodeError('invalid_keyword_id', { id => $key_id });
|| ThrowUserError('invalid_keyword_id', { id => $key_id });
$keyword->set_all({
name => scalar $cgi->param('name'),
......@@ -140,7 +140,7 @@ if ($action eq 'update') {
if ($action eq 'del') {
my $keyword = new Bugzilla::Keyword($key_id)
|| ThrowCodeError('invalid_keyword_id', { id => $key_id });
|| ThrowUserError('invalid_keyword_id', { id => $key_id });
$vars->{'keyword'} = $keyword;
$vars->{'token'} = issue_session_token('delete_keyword');
......@@ -154,7 +154,7 @@ if ($action eq 'del') {
if ($action eq 'delete') {
check_token_data($token, 'delete_keyword');
my $keyword = new Bugzilla::Keyword($key_id)
|| ThrowCodeError('invalid_keyword_id', { id => $key_id });
|| ThrowUserError('invalid_keyword_id', { id => $key_id });
$keyword->remove_from_db();
......
......@@ -701,7 +701,7 @@ sub check_user {
$otherUser = new Bugzilla::User({ name => $otherUserLogin });
$vars->{'user_login'} = $otherUserLogin;
}
($otherUser && $otherUser->id) || ThrowCodeError('invalid_user', $vars);
($otherUser && $otherUser->id) || ThrowUserError('invalid_user', $vars);
return $otherUser;
}
......
......@@ -16,7 +16,7 @@ use Bugzilla::Error;
use Bugzilla::WebService::Constants;
BEGIN {
if (!Bugzilla->feature('jsonrpc')) {
ThrowCodeError('feature_disabled', { feature => 'jsonrpc' });
ThrowUserError('feature_disabled', { feature => 'jsonrpc' });
}
}
use Bugzilla::WebService::Server::JSONRPC;
......
......@@ -54,13 +54,13 @@ if ($id) {
# Be careful not to allow directory traversal.
if ($id =~ /\.\./) {
# two dots in a row is bad
ThrowCodeError("bad_page_cgi_id", { "page_id" => $id });
ThrowUserError("bad_page_cgi_id", { "page_id" => $id });
}
# Split into name and ctype.
$id =~ /^([\w\-\/\.]+)\.(\w+)$/;
if (!$2) {
# if this regexp fails to match completely, something bad came in
ThrowCodeError("bad_page_cgi_id", { "page_id" => $id });
ThrowUserError("bad_page_cgi_id", { "page_id" => $id });
}
my %vars = (
......
......@@ -199,8 +199,6 @@ $vars->{'bug'} = $bug;
Bugzilla::Hook::process('post_bug_after_creation', { vars => $vars });
ThrowCodeError("bug_error", { bug => $bug }) if $bug->error;
my $recipients = { changer => $user };
my $bug_sent = Bugzilla::BugMail::Send($id, $recipients);
$bug_sent->{type} = 'created';
......
......@@ -123,8 +123,7 @@ if ($action eq "delete") {
action => "delete",
object => "quips"});
my $quipid = $cgi->param("quipid");
ThrowCodeError("need_quipid") unless $quipid =~ /(\d+)/;
$quipid = $1;
detaint_natural($quipid) || ThrowUserError("need_quipid");
check_hash_token($token, ['quips', $quipid]);
($vars->{'deleted_quip'}) = $dbh->selectrow_array(
......
......@@ -110,11 +110,11 @@ my $width = $cgi->param('width') || 1024;
my $height = $cgi->param('height') || 600;
(detaint_natural($width) && $width > 0)
|| ThrowCodeError("invalid_dimensions");
|| ThrowUserError("invalid_dimensions");
$width <= 2000 || ThrowUserError("chart_too_large");
(detaint_natural($height) && $height > 0)
|| ThrowCodeError("invalid_dimensions");
|| ThrowUserError("invalid_dimensions");
$height <= 2000 || ThrowUserError("chart_too_large");
my $formatparam = $cgi->param('format') || '';
......@@ -131,7 +131,7 @@ if ($formatparam eq "table") {
}
else {
if (!Bugzilla->feature('graphical_reports')) {
ThrowCodeError('feature_disabled', { feature => 'graphical_reports' });
ThrowUserError('feature_disabled', { feature => 'graphical_reports' });
}
if ($row_field && !$col_field) {
......@@ -147,13 +147,13 @@ my $valid_columns = Bugzilla::Search::REPORT_COLUMNS;
# Validate the values in the axis fields or throw an error.
!$row_field
|| ($valid_columns->{$row_field} && trick_taint($row_field))
|| ThrowCodeError("report_axis_invalid", {fld => "x", val => $row_field});
|| ThrowUserError("report_axis_invalid", {fld => "x", val => $row_field});
!$col_field
|| ($valid_columns->{$col_field} && trick_taint($col_field))
|| ThrowCodeError("report_axis_invalid", {fld => "y", val => $col_field});
|| ThrowUserError("report_axis_invalid", {fld => "y", val => $col_field});
!$tbl_field
|| ($valid_columns->{$tbl_field} && trick_taint($tbl_field))
|| ThrowCodeError("report_axis_invalid", {fld => "z", val => $tbl_field});
|| ThrowUserError("report_axis_invalid", {fld => "z", val => $tbl_field});
my @axis_fields = grep { $_ } ($row_field, $col_field, $tbl_field);
......
......@@ -31,7 +31,7 @@ my $product_all = {id => 0};
bless($product_all, 'Bugzilla::Product');
if (!Bugzilla->feature('old_charts')) {
ThrowCodeError('feature_disabled', { feature => 'old_charts' });
ThrowUserError('feature_disabled', { feature => 'old_charts' });
}
my $dir = bz_locations()->{'datadir'} . "/mining";
......
......@@ -81,7 +81,7 @@ sub AddLink {
}
}
ThrowCodeError("missing_bug_id") if !defined $cgi->param('id');
ThrowUserError("missing_bug_id") unless $cgi->param('id');
# The list of valid directions. Some are not proposed in the dropdrown
# menu despite the fact that they are valid.
......
......@@ -40,11 +40,6 @@
The result value of [% value FILTER html %] was not handled by
the login code.
[% ELSIF error == "bad_page_cgi_id" %]
[% title = "Invalid Page ID" %]
The ID <code>[% page_id FILTER html %]</code> is not a
valid page identifier.
[% ELSIF error == "bad_arg" %]
Bad argument <code>[% argument FILTER html %]</code> sent to
<code>[% function FILTER html %]</code> function.
......@@ -128,11 +123,6 @@
address.
[% END %]
[% ELSIF error == "extension_disabled" %]
[% title = "Extension Disabled" %]
You cannot access this page because the extension '[% name FILTER html %]'
is disabled.
[% ELSIF error == "extension_must_be_subclass" %]
<code>[% package FILTER html %]</code> from
<code>[% filename FILTER html %]</code> is not a subclass of
......@@ -179,28 +169,13 @@
[% title = "Field Type Not Specified" %]
You must specify a type when creating a custom field.
[% ELSIF error == "illegal_content_type_method" %]
Your form submission got corrupted somehow. The <em>content
method</em> field, which specifies how the content type gets determined,
should have been either <em>autodetect</em>, <em>list</em>,
or <em>manual</em>, but was instead
<em>[% contenttypemethod FILTER html %]</em>.
[% ELSIF error == "illegal_field" %]
A legal [% field FILTER html %] was not set.
[% ELSIF error == "invalid_attach_id_to_obsolete" %]
The attachment number of one of the attachments you wanted to obsolete,
[%+ attach_id FILTER html %], is invalid.
[% ELSIF error == "invalid_customfield_type" %]
[% title = "Invalid Field Type" %]
The type <em>[% type FILTER html %]</em> is not a valid field type.
[% ELSIF error == "invalid_dimensions" %]
[% title = "Invalid Dimensions" %]
The width or height specified is not a positive integer.
[% ELSIF error == "invalid_feature" %]
[% title = "Invalid Feature Name" %]
[% feature FILTER html %] is not a valid feature name. See
......@@ -229,31 +204,11 @@
There is no such group: [% group FILTER html %]. Check your $webservergroup
setting in [% constants.bz_locations.localconfig FILTER html %].
[% ELSIF error == "mismatched_bug_ids_on_obsolete" %]
Attachment [% attach_id FILTER html %] ([% description FILTER html %])
is attached to [% terms.bug %] [%+ attach_bug_id FILTER html %],
but you tried to flag it as obsolete while creating a new attachment to
[%+ terms.bug %] [%+ my_bug_id FILTER html %].
[% ELSIF error == "feature_disabled" %]
The [% install_string("feature_$feature") FILTER html %] feature is not
available in this [% terms.Bugzilla %].
[% IF user.in_group('admin') %]
If you would like to enable this feature, please run
<kbd>checksetup.pl</kbd> to see how to install the necessary
requirements for this feature.
[% END %]
[% ELSIF error == "flag_unexpected_object" %]
[% title = "Object Not Recognized" %]
Flags cannot be set for objects of type [% caller FILTER html %].
They can only be set for [% terms.bugs %] and attachments.
[% ELSIF error == "flag_requestee_disabled" %]
[% title = "Flag not Requestable from Specific Person" %]
You can't ask a specific person for
<em>[% type.name FILTER html %]</em>.
[% ELSIF error == "flag_type_inactive" %]
[% title = "Inactive Flag Type" %]
The flag type [% type FILTER html %] is inactive and cannot be used
......@@ -266,21 +221,6 @@
[% ELSIF error == "invalid_field_name" %]
Can't use [% field FILTER html %] as a field name.
[% ELSIF error == "invalid_keyword_id" %]
The keyword ID <em>[% id FILTER html %]</em> couldn't be
found.
[% ELSIF error == "invalid_user" %]
[% title = "Invalid User" %]
There is no user account
[% IF user_id %]
with ID <em>[% user_id FILTER html %]</em>.
[% ELSIF user_login %]
with login name <em>[% user_login FILTER html %]</em>.
[% ELSE %]
given.
[% END %]
[% ELSIF error == "jobqueue_insert_failed" %]
[% title = "Job Queue Failure" %]
Inserting a <code>[% job FILTER html %]</code> job into the Job
......@@ -322,17 +262,11 @@
to '[% mail.header('To') FILTER html %]':
[%+ msg FILTER html %]
[% ELSIF error == "missing_bug_id" %]
No [% terms.bug %] ID was given.
[% ELSIF error == "missing_series_id" %]
Having inserted a series into the database, no series_id was returned for
it. Series: [% series.category FILTER html %] /
[%+ series.subcategory FILTER html %] /
[%+ series.name FILTER html %].
[% ELSIF error == "need_quipid" %]
A valid quipid is needed.
[% ELSIF error == "object_dep_sort_loop" %]
There is a loop in VALIDATOR_DEPENDENCIES involving
......@@ -391,13 +325,6 @@
An error occurred while preparing for a RADIUS authentication request:
<code>[% errstr FILTER html %]</code>.
[% ELSIF error == "report_axis_invalid" %]
<em>[% val FILTER html %]</em> is not a valid value for
[%+ IF fld == "x" %]the horizontal axis
[%+ ELSIF fld == "y" %]the vertical axis
[%+ ELSIF fld == "z" %]the multiple tables/images
[%+ ELSE %]a report axis[% END %] field.
[% ELSIF error == "search_cp_without_op" %]
Search argument f[% id FILTER html %] is "CP" but there is no
matching "OP" before it.
......
......@@ -225,6 +225,11 @@
[% title = "Attachment Removed" %]
The attachment you are attempting to access has been removed.
[% ELSIF error == "bad_page_cgi_id" %]
[% title = "Invalid Page ID" %]
The ID <code>[% page_id FILTER html %]</code> is not a
valid page identifier.
[% ELSIF error == "bug_access_denied" %]
[% title = "$terms.Bug Access Denied" %]
[% admindocslinks = {'groups.html' => 'Group Security'} %]
......@@ -456,10 +461,24 @@
[% ELSIF error == "extension_create_no_name" %]
You must specify a name for your extension, as an argument to this script.
[% ELSIF error == "extension_disabled" %]
[% title = "Extension Disabled" %]
You cannot access this page because the extension '[% name FILTER html %]'
is disabled.
[% ELSIF error == "extension_first_letter_caps" %]
The first letter of your extension's name must be a capital letter.
(You specified '[% name FILTER html %]'.)
[% ELSIF error == "feature_disabled" %]
The [% install_string("feature_$feature") FILTER html %] feature is not
available in this [% terms.Bugzilla %].
[% IF user.in_group('admin') %]
If you would like to enable this feature, please run
<kbd>checksetup.pl</kbd> to see how to install the necessary
requirements for this feature.
[% END %]
[% ELSIF error == "field_already_exists" %]
[% title = "Field Already Exists" %]
The field '[% field.name FILTER html %]'
......@@ -614,6 +633,10 @@
<br>Alternately, if your attachment is an image, you could convert
it to a compressible format like JPG or PNG and try again.
[% ELSIF error == "flag_requestee_disabled" %]
[% title = "Flag not Requestable from Specific Person" %]
You can't ask a specific person for <em>[% type.name FILTER html %]</em>.
[% ELSIF error == "flag_requestee_needs_privs" %]
[% title = "Flag Requestee Needs Privileges" %]
[% requestee.identity FILTER html %] does not have permission to set the
......@@ -937,6 +960,10 @@
Invalid datasets <em>[% datasets.join(":") FILTER html %]</em>. Only digits,
letters and colons are allowed.
[% ELSIF error == "invalid_dimensions" %]
[% title = "Invalid Dimensions" %]
The width or height specified is not a positive integer.
[% ELSIF error == "invalid_format" %]
[% title = "Invalid Format" %]
The format "[% format FILTER html %]" is invalid (must be one of
......@@ -953,6 +980,9 @@
[% title = "Invalid group name" %]
The group you specified, [% name FILTER html %], is not valid here.
[% ELSIF error == "invalid_keyword_id" %]
The keyword ID <em>[% id FILTER html %]</em> couldn't be found.
[% ELSIF error == "invalid_maxrows" %]
[% title = "Invalid Max Rows" %]
The maximum number of rows, '[% maxrows FILTER html %]', must be
......@@ -966,6 +996,17 @@
[% title = "Invalid regular expression" %]
The regular expression you entered is invalid.
[% ELSIF error == "invalid_user" %]
[% title = "Invalid User" %]
There is no user account
[% IF user_id %]
with ID <em>[% user_id FILTER html %]</em>.
[% ELSIF user_login %]
with login name <em>[% user_login FILTER html %]</em>.
[% ELSE %]
given.
[% END %]
[% ELSIF error == "invalid_user_group" %]
[% title = "Invalid User Group" %]
[% IF users.size > 1 %] Users [% ELSE %] User [% END %]
......@@ -1106,11 +1147,20 @@
[% title = "Misarranged Dates" %]
Your start date ([% datefrom FILTER html %]) is after
your end date ([% dateto FILTER html %]).
[% ELSIF error == "mismatched_bug_ids_on_obsolete" %]
Attachment [% attach_id FILTER html %] is attached to another [% terms.bug %],
but you tried to flag it as obsolete while creating a new attachment to
[%+ terms.bug %] [%+ my_bug_id FILTER html %].
[% ELSIF error == "missing_attachment_description" %]
[% title = "Missing Attachment Description" %]
You must enter a description for the attachment.
[% ELSIF error == "missing_bug_id" %]
[% title = "Missing $terms.Bug ID" %]
No [% terms.bug %] ID was given.
[% ELSIF error == "missing_category" %]
[% title = "Missing Category" %]
You did not specify a category for this series.
......@@ -1135,13 +1185,7 @@
You asked [% terms.Bugzilla %] to auto-detect the content type, but
your browser did not specify a content type when uploading the file,
so you must enter a content type manually.
[% ELSIF error == "missing_content_type_method" %]
[% title = "Missing Content-Type Determination Method" %]
You must choose a method for determining the content type,
either <em>auto-detect</em>, <em>select from list</em>, or <em>enter
manually</em>.
[% ELSIF error == "missing_cookie" %]
[% title = "Missing Cookie" %]
Sorry, I seem to have lost the cookie that recorded
......@@ -1174,6 +1218,10 @@
does not exist.
[% END %]
[% ELSIF error == "need_quipid" %]
[% title = "Missing Quip ID" %]
A valid quip ID is needed.
[% ELSIF error == "missing_resolution" %]
[% title = "Resolution Required" %]
A valid resolution is required to mark [% terms.bugs %] as
......@@ -1485,6 +1533,14 @@
To reassign [% terms.abug %], you must provide an address for
the new assignee.
[% ELSIF error == "report_axis_invalid" %]
[% title = "Invalid Axis" %]
<em>[% val FILTER html %]</em> is not a valid value for
[%+ IF fld == "x" %]the horizontal axis
[%+ ELSIF fld == "y" %]the vertical axis
[%+ ELSIF fld == "z" %]the multiple tables/images
[%+ ELSE %]a report axis[% END %] field.
[% ELSIF error == "report_name_missing" %]
[% title = "No Report Name Specified" %]
You must enter a name for your report.
......
......@@ -17,7 +17,7 @@ use Bugzilla;
use Bugzilla::Error;
my $is_enabled = grep { $_->NAME eq 'Voting' } @{ Bugzilla->extensions };
$is_enabled || ThrowCodeError('extension_disabled', { name => 'Voting' });
$is_enabled || ThrowUserError('extension_disabled', { name => 'Voting' });
my $cgi = Bugzilla->cgi;
my $action = $cgi->param('action') || 'show_user';
......
......@@ -16,7 +16,7 @@ use Bugzilla::Error;
use Bugzilla::WebService::Constants;
BEGIN {
if (!Bugzilla->feature('xmlrpc')) {
ThrowCodeError('feature_disabled', { feature => 'xmlrpc' });
ThrowUserError('feature_disabled', { feature => 'xmlrpc' });
}
}
use Bugzilla::WebService::Server::XMLRPC;
......
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