resourceloader: Write to debug log for all fatal errors
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 2 May 2013 01:27:58 +0000 (03:27 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 20 May 2013 19:39:27 +0000 (19:39 +0000)
There's various fatal errors that can happen in ResourceLoader.
Since in a javascript/css response there is no error page we can
show, we currently catch them all and output them in a block
comment on top of load.php.

This maintains valid syntax for the response and keeps the error
easy to view (if you're looking for it in the browser).

However from a debugging perspective it is a nightmare. Literally
the only visible difference from a normal request response is
the cache maxage (if hasErrors: use unversionsed maxage).

For all errors we currently already catch and write to request
response outpout, also write to debug log.

This also helps in fixing bug #.

This commit basically changes the following pattern:

    // Add exception to the output as a comment
    $errors .= $this->makeComment( $e->__toString() );
    $this->hasErrors = true;

to:

    wfDebugLog( 'resourceloader', __METHOD__ . ": <failure summary>: $e\n" );
    $this->hasErrors = true;
    // Add exception to the output as a comment
    $errors .= $this->makeComment( $e->__toString() );

Bug: 44018
Change-Id: I684f6492f839a6c6adb07b0640e88cfea21fcf60

includes/resourceloader/ResourceLoader.php

index a3c3b10..e4fd982 100644 (file)
@@ -174,9 +174,10 @@ class ResourceLoader {
                        // Save filtered text to Memcached
                        $cache->set( $key, $result );
                } catch ( Exception $exception ) {
+                       wfDebugLog( 'resourceloader', __METHOD__ . ": minification failed: $e" );
+                       $this->hasErrors = true;
                        // Return exception as a comment
                        $result = $this->makeComment( $exception->__toString() );
-                       $this->hasErrors = true;
                }
 
                wfProfileOut( __METHOD__ );
@@ -453,8 +454,11 @@ class ResourceLoader {
                                // Do not allow private modules to be loaded from the web.
                                // This is a security issue, see bug 34907.
                                if ( $module->getGroup() === 'private' ) {
-                                       $errors .= $this->makeComment( "Cannot show private module \"$name\"" );
+                                       wfDebugLog( 'resourceloader', __METHOD__ . ": request for private module denied: $e" );
                                        $this->hasErrors = true;
+                                       // Add exception to the output as a comment
+                                       $errors .= $this->makeComment( "Cannot show private module \"$name\"" );
+
                                        continue;
                                }
                                $modules[$name] = $module;
@@ -467,9 +471,10 @@ class ResourceLoader {
                try {
                        $this->preloadModuleInfo( array_keys( $modules ), $context );
                } catch ( Exception $e ) {
+                       wfDebugLog( 'resourceloader', __METHOD__ . ": preloading module info failed: $e" );
+                       $this->hasErrors = true;
                        // Add exception to the output as a comment
                        $errors .= $this->makeComment( $e->__toString() );
-                       $this->hasErrors = true;
                }
 
                wfProfileIn( __METHOD__ . '-getModifiedTime' );
@@ -485,9 +490,10 @@ class ResourceLoader {
                                // Calculate maximum modified time
                                $mtime = max( $mtime, $module->getModifiedTime( $context ) );
                        } catch ( Exception $e ) {
+                               wfDebugLog( 'resourceloader', __METHOD__ . ": calculating maximum modified time failed: $e" );
+                               $this->hasErrors = true;
                                // Add exception to the output as a comment
                                $errors .= $this->makeComment( $e->__toString() );
-                               $this->hasErrors = true;
                        }
                }
 
@@ -694,9 +700,10 @@ class ResourceLoader {
                        try {
                                $blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() );
                        } catch ( Exception $e ) {
+                               wfDebugLog( 'resourceloader', __METHOD__ . ": pre-fetching blobs from MessageBlobStore failed: $e" );
+                               $this->hasErrors = true;
                                // Add exception to the output as a comment
                                $exceptions .= $this->makeComment( $e->__toString() );
-                               $this->hasErrors = true;
                        }
                } else {
                        $blobs = array();
@@ -800,9 +807,10 @@ class ResourceLoader {
                                                break;
                                }
                        } catch ( Exception $e ) {
+                               wfDebugLog( 'resourceloader', __METHOD__ . ": generating module package failed: $e" );
+                               $this->hasErrors = true;
                                // Add exception to the output as a comment
                                $exceptions .= $this->makeComment( $e->__toString() );
-                               $this->hasErrors = true;
 
                                // Register module as missing
                                $missing[] = $name;