From c5813d15b853b9463f545c2db94e3ee86a2ee68c Mon Sep 17 00:00:00 2001 From: "bugreport%peshkin.net" Date: Mon, 8 Nov 2004 02:25:59 +0000 Subject: [PATCH] Bug 257344: Remove exit from error handlers when non-interactive r=glob,justdave a=justdave --- webtools/bugzilla/Bugzilla.pm | 17 +++++++++++++++++ webtools/bugzilla/Bugzilla/Error.pm | 18 +++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/webtools/bugzilla/Bugzilla.pm b/webtools/bugzilla/Bugzilla.pm index 1c2a6a4b062..e8763960831 100644 --- a/webtools/bugzilla/Bugzilla.pm +++ b/webtools/bugzilla/Bugzilla.pm @@ -111,6 +111,16 @@ sub dbh { return $_dbh; } +my $_batch; +sub batch { + my $class = shift; + my $newval = shift; + if ($newval) { + $_batch = $newval; + } + return $_batch || 0; +} + sub dbwritesallowed { my $class = shift; @@ -282,6 +292,13 @@ Essentially, causes calls to Cuser> to return C. This has the effect of logging out a user for the current request only; cookies and database sessions are left intact. +=item C + +Set to true, by calling Bugzilla->batch(1), to indicate that Bugzilla is +being called in a non-interactive manner and errors should be passed to +die() rather than being sent to a browser and finished with an exit(). +Bugzilla->batch will return the current state of this flag. + =item C The current database handle. See L. diff --git a/webtools/bugzilla/Bugzilla/Error.pm b/webtools/bugzilla/Bugzilla/Error.pm index 25527f59934..00a2675eb05 100644 --- a/webtools/bugzilla/Bugzilla/Error.pm +++ b/webtools/bugzilla/Bugzilla/Error.pm @@ -69,12 +69,17 @@ sub _throw_error { close ERRORLOGFID; } - print Bugzilla->cgi->header(); - my $template = Bugzilla->template; - $template->process($name, $vars) - || ThrowTemplateError($template->error()); - + if (Bugzilla->batch) { + my $message; + $template->process($name, $vars, \$message) + || ThrowTemplateError($template->error()); + die("$message"); + } else { + print Bugzilla->cgi->header(); + $template->process($name, $vars) + || ThrowTemplateError($template->error()); + } exit; } @@ -90,6 +95,9 @@ sub ThrowTemplateError { my ($template_err) = @_; my $vars = {}; + if (Bugzilla->batch) { + die("error: template error: $template_err"); + } $vars->{'template_error_msg'} = $template_err; $vars->{'error'} = "template_error";