Merge "Replace wgShowExceptionDetails with wgShowDBErrorBacktrace on db errors"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 21 Nov 2016 22:27:38 +0000 (22:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 21 Nov 2016 22:27:38 +0000 (22:27 +0000)
1  2 
includes/exception/MWExceptionRenderer.php

@@@ -61,8 -61,7 +61,7 @@@ class MWExceptionRenderer 
                                                "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $eNew );
                                } else {
                                        $message .= "Exception caught inside exception handler.\n\n" .
-                                               "Set \$wgShowExceptionDetails = true; at the bottom of LocalSettings.php " .
-                                               "to show detailed debugging information.";
+                                               self::getShowBacktraceError( $e );
                                }
                                $message .= "\n";
                        } else {
                                        $message = MWExceptionHandler::getPublicLogMessage( $e );
                                }
                        }
 -                      if ( self::isCommandLine() ) {
 -                              self::printError( $message );
 -                      } else {
 -                              echo nl2br( htmlspecialchars( $message ) ) . "\n";
 -                      }
 +                      echo nl2br( htmlspecialchars( $message ) ) . "\n";
                }
        }
  
                                        $logId,
                                        MWExceptionHandler::getURL()
                                ) . "</div>\n" .
-                       "<!-- Set \$wgShowExceptionDetails = true; " .
-                       "at the bottom of LocalSettings.php to show detailed " .
-                       "debugging information. -->";
+                               "<!-- " . wordwrap( self::getShowBacktraceError( $e ), 50 ) . " -->";
                }
  
                return $html;
                                "\nBacktrace:\n" .
                                MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n";
                } else {
-                       return "Set \$wgShowExceptionDetails = true; " .
-                               "in LocalSettings.php to show detailed debugging information.\n";
+                       return self::getShowBacktraceError( $e );
                }
        }
  
                );
        }
  
+       /**
+        * @param Exception|Throwable $e
+        * @return string
+        */
+       private static function getShowBacktraceError( $e ) {
+               global $wgShowExceptionDetails, $wgShowDBErrorBacktrace;
+               $vars = [];
+               if ( !$wgShowExceptionDetails ) {
+                       $vars[] = '$wgShowExceptionDetails = true;';
+               }
+               if ( $e instanceof DBError && !$wgShowDBErrorBacktrace ) {
+                       $vars[] = '$wgShowDBErrorBacktrace = true;';
+               }
+               $vars = implode( ' and ', $vars );
+               return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information";
+       }
        /**
         * @return bool
         */