]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 257344: Remove exit from error handlers when non-interactive
authorbugreport%peshkin.net <>
Mon, 8 Nov 2004 10:25:58 +0000 (10:25 +0000)
committerbugreport%peshkin.net <>
Mon, 8 Nov 2004 10:25:58 +0000 (10:25 +0000)
r=glob,justdave
a=justdave

Bugzilla.pm
Bugzilla/Error.pm

index 1c2a6a4b062fddaed231509daa32d652d6193367..e8763960831249cc3af2df69692511565b0c44cd 100644 (file)
@@ -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 C<Bugzilla->user> to return C<undef>. This has the
 effect of logging out a user for the current request only; cookies and
 database sessions are left intact.
 
+=item C<batch>
+
+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<dbh>
 
 The current database handle. See L<DBI>.
index 25527f599348b9965a101f9523eb3a63c0eb3e7b..00a2675eb05c8f51e71f41a6435952544c2fb233 100644 (file)
@@ -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";