Nicer looking errors in command line mode
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 26 Jun 2004 03:28:58 +0000 (03:28 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 26 Jun 2004 03:28:58 +0000 (03:28 +0000)
includes/Database.php
includes/GlobalFunctions.php

index a103e32..f382485 100644 (file)
@@ -157,7 +157,7 @@ class Database {
        # If errors are explicitly ignored, returns success
        function query( $sql, $fname = "" )
        {
-               global $wgProfiling;
+               global $wgProfiling, $wgCommandLineMode;
                
                if ( $wgProfiling ) {
                        # generalizeSQL will probably cut down the query to reasonable
@@ -186,7 +186,13 @@ class Database {
                                wfDebug("SQL ERROR (ignored): " . $error . "\n");
                        } else {
                                wfDebug("SQL ERROR: " . $error . "\n");
-                               if ( $this->mOut ) {
+                               if ( $wgCommandLineMode ) {
+                                       wfDebugDieBacktrace( "A database error has occurred\n" .
+                                         "Query: $sql\n" .
+                                         "Function: $fname\n" .
+                                         "Error: $errno $error\n"
+                                       );
+                               } elseif ( $this->mOut ) {
                                        // this calls wfAbruptExit()
                                        $this->mOut->databaseError( $fname, $sql, $error, $errno );                             
                                }
index 08b9162..dd5197d 100644 (file)
@@ -370,15 +370,31 @@ function wfAbruptExit(){
 }
 
 function wfDebugDieBacktrace( $msg = '' ) {
+       global $wgCommandLineMode;
+
        if ( function_exists( 'debug_backtrace' ) ) {
-               $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
+               if ( $wgCommandLineMode ) {
+                       $msg .= "\nBacktrace:\n";
+               } else {
+                       $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
+               }
                $backtrace = debug_backtrace();
                foreach( $backtrace as $call ) {
                        $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
                        $file = $f[count($f)-1];
-                       $msg .= '<li>' . $file . " line " . $call['line'] . ', in ';
+                       if ( $wgCommandLineMode ) {
+                               $msg .= "$file line {$call['line']}, in ";
+                       } else {
+                               $msg .= '<li>' . $file . " line " . $call['line'] . ', in ';
+                       }
                        if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
-                       $msg .= $call['function'] . "()</li>\n";
+                       $msg .= $call['function'] . "()";
+                       
+                       if ( $wgCommandLineMode ) {
+                               $msg .= "\n";
+                       } else {
+                               $msg .= "</li>\n";
+                       }
                }
         }
         die( $msg );