registration: Throw an Exception if a JSON file is invalid
authorKunal Mehta <legoktm@gmail.com>
Wed, 11 Feb 2015 00:39:24 +0000 (16:39 -0800)
committerKunal Mehta <legoktm@gmail.com>
Wed, 11 Feb 2015 01:29:11 +0000 (17:29 -0800)
Currently you get confusing fatals like:
 Argument 2 passed to ExtensionRegistry::processAutoLoader() must
 be an array, null given

Change-Id: Icc7198db152e071c5a42e06547268fbaee916107

includes/registration/ExtensionRegistry.php

index 4605ca5..8541e31 100644 (file)
@@ -96,6 +96,9 @@ class ExtensionRegistry {
                        foreach ( $this->queued as $path => $mtime ) {
                                $json = file_get_contents( $path );
                                $info = json_decode( $json, /* $assoc = */ true );
+                               if ( !is_array( $info ) ) {
+                                       throw new Exception( "$path is not a valid JSON file." );
+                               }
                                $autoload = $this->processAutoLoader( dirname( $path ), $info );
                                // Set up the autoloader now so custom processors will work
                                $GLOBALS['wgAutoloadClasses'] += $autoload;