From 2a6f7d4663dfc5cb00c1bb8b8d8139869a22d461 Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Mon, 12 Nov 2012 18:46:48 +0100 Subject: Bug 676844: Replace ThrowCodeError() by ThrowUserError() when the error is not triggered by the code itself r=glob a=LpSolit --- Bugzilla/Attachment.pm | 33 ++++++++++++++------------------- Bugzilla/Flag.pm | 4 ++-- Bugzilla/JobQueue.pm | 2 +- Bugzilla/Util.pm | 2 +- 4 files changed, 18 insertions(+), 23 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm index 1c524c24b..982435a3a 100644 --- a/Bugzilla/Attachment.pm +++ b/Bugzilla/Attachment.pm @@ -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; } diff --git a/Bugzilla/Flag.pm b/Bugzilla/Flag.pm index 21241da5f..867e08a02 100644 --- a/Bugzilla/Flag.pm +++ b/Bugzilla/Flag.pm @@ -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. diff --git a/Bugzilla/JobQueue.pm b/Bugzilla/JobQueue.pm index 18723446c..faf06c476 100644 --- a/Bugzilla/JobQueue.pm +++ b/Bugzilla/JobQueue.pm @@ -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; diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 197a81af4..db25cd27c 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -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'; -- cgit v1.2.3-24-g4f1b