From 4e7e3310242bd5264b5f48e4bf3c387e59288b85 Mon Sep 17 00:00:00 2001 From: "bbaetz%acm.org" <> Date: Sun, 14 Sep 2003 13:04:38 +0000 Subject: Bug 208699 - Move Throw{Code,Template}Error into Error.pm r,a=justdave --- Bugzilla/Error.pm | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 7 deletions(-) (limited to 'Bugzilla/Error.pm') diff --git a/Bugzilla/Error.pm b/Bugzilla/Error.pm index a23d6db15..e511a575c 100644 --- a/Bugzilla/Error.pm +++ b/Bugzilla/Error.pm @@ -19,16 +19,18 @@ # # Contributor(s): Bradley Baetz -use strict; - package Bugzilla::Error; +use strict; use base qw(Exporter); -@Bugzilla::Error::EXPORT = qw(ThrowUserError); +@Bugzilla::Error::EXPORT = qw(ThrowCodeError ThrowTemplateError ThrowUserError); -sub ThrowUserError { - my ($error, $vars, $unlock_tables) = @_; +use Bugzilla::Config; +use Bugzilla::Util; + +sub _throw_error { + my ($name, $error, $vars, $unlock_tables) = @_; $vars ||= {}; @@ -39,12 +41,56 @@ sub ThrowUserError { print Bugzilla->cgi->header(); my $template = Bugzilla->template; - $template->process("global/user-error.html.tmpl", $vars) - || &::ThrowTemplateError($template->error()); + $template->process($name, $vars) + || ThrowTemplateError($template->error()); exit; } +sub ThrowUserError { + _throw_error("global/user-error.html.tmpl", @_); +} + +sub ThrowCodeError { + _throw_error("global/code-error.html.tmpl", @_); +} + +sub ThrowTemplateError { + my ($template_err) = @_; + + my $vars = {}; + + $vars->{'template_error_msg'} = $template_err; + $vars->{'error'} = "template_error"; + + my $template = Bugzilla->template; + + # 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 < +

+ 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. +

+ +

Template->process() failed twice.
+ First error: $error
+ Second error: $error2

+ +END + } + exit; +} + 1; __END__ @@ -82,6 +128,25 @@ error handling code will unlock the database tables. In the long term, this argument will go away, to be replaced by transactional C calls. There is no timeframe for doing so, however. +=item C + +This function is used when an internal check detects an error of some sort. +This usually indicates a bug in Bugzilla, although it can occur if the user +manually constructs urls without correct parameters. + +This function's behaviour is similar to C, except that the +template used to display errors is I. In addition +if the hashref used as the optional second argument contains a key I +then the contents of the hashref (which is expected to be another hashref) will +be displayed after the error message, as a debugging aid. + +=item C + +This function should only be called if a Cprocess()> 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 to +a print statement as a last-ditch error. + =back =head1 SEE ALSO -- cgit v1.2.3-24-g4f1b