Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312030

Change subject: Use standard exceptions in ObjectCache and always handle 
CACHE_NONE/"hash"
......................................................................

Use standard exceptions in ObjectCache and always handle CACHE_NONE/"hash"

In cache CACHE_NONE or "hash" is not set yet or was unset,
return the proper new object anyway for sanity.

Change-Id: I36108a865273b9c209145828e5e1216b545ef431
---
M includes/objectcache/ObjectCache.php
1 file changed, 14 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/30/312030/1

diff --git a/includes/objectcache/ObjectCache.php 
b/includes/objectcache/ObjectCache.php
index ea237aa..8bf1220 100644
--- a/includes/objectcache/ObjectCache.php
+++ b/includes/objectcache/ObjectCache.php
@@ -118,13 +118,20 @@
         *
         * @param string $id A key in $wgObjectCaches.
         * @return BagOStuff
-        * @throws MWException
+        * @throws InvalidArgumentException
         */
        public static function newFromId( $id ) {
                global $wgObjectCaches;
 
                if ( !isset( $wgObjectCaches[$id] ) ) {
-                       throw new MWException( "Invalid object cache type 
\"$id\" requested. " .
+                       // Always recognize these ones
+                       if ( $id === CACHE_NONE ) {
+                               return new EmptyBagOStuff();
+                       } elseif ( $id === 'hash' ) {
+                               return new HashBagOStuff();
+                       }
+
+                       throw new InvalidArgumentException( "Invalid object 
cache type \"$id\" requested. " .
                                "It is not present in \$wgObjectCaches." );
                }
 
@@ -160,7 +167,7 @@
         *  - loggroup: Alias to set 'logger' key with LoggerFactory group.
         *  - .. Other parameters passed to factory or class.
         * @return BagOStuff
-        * @throws MWException
+        * @throws InvalidArgumentException
         */
        public static function newFromParams( $params ) {
                if ( isset( $params['loggroup'] ) ) {
@@ -217,7 +224,7 @@
                        }
                        return new $class( $params );
                } else {
-                       throw new MWException( "The definition of cache type \""
+                       throw new InvalidArgumentException( "The definition of 
cache type \""
                                . print_r( $params, true ) . "\" lacks both "
                                . "factory and class parameters." );
                }
@@ -270,7 +277,7 @@
         *
         * @param int|string|array $fallback Fallback cache or parameter map 
with 'fallback'
         * @return BagOStuff
-        * @throws MWException
+        * @throws InvalidArgumentException
         * @since 1.27
         */
        public static function getLocalServerInstance( $fallback = CACHE_NONE ) 
{
@@ -315,13 +322,13 @@
         * @since 1.26
         * @param string $id A key in $wgWANObjectCaches.
         * @return WANObjectCache
-        * @throws MWException
+        * @throws InvalidArgumentException
         */
        public static function newWANCacheFromId( $id ) {
                global $wgWANObjectCaches;
 
                if ( !isset( $wgWANObjectCaches[$id] ) ) {
-                       throw new MWException( "Invalid object cache type 
\"$id\" requested. " .
+                       throw new InvalidArgumentException( "Invalid object 
cache type \"$id\" requested. " .
                                "It is not present in \$wgWANObjectCaches." );
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/312030
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I36108a865273b9c209145828e5e1216b545ef431
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to