jenkins-bot has submitted this change and it was merged.

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


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

* If cache CACHE_NONE or "hash" is not set yet or was unset,
  return the proper new object anyway for sanity.
* Also fixed $params typo in newFromParams(). This should not
  have any effect since SqlBagOStuff ignores the key in this case.
* Removed excess "use" statement.

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

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/objectcache/ObjectCache.php 
b/includes/objectcache/ObjectCache.php
index ea237aa..14809a8 100644
--- a/includes/objectcache/ObjectCache.php
+++ b/includes/objectcache/ObjectCache.php
@@ -23,7 +23,6 @@
 
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
-use MediaWiki\Services\ServiceDisabledException;
 
 /**
  * Functions to get cache objects
@@ -118,13 +117,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 +166,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'] ) ) {
@@ -187,7 +193,7 @@
                        if ( is_subclass_of( $class, SqlBagOStuff::class ) ) {
                                if ( isset( $params['server'] ) && !isset( 
$params['servers'] ) ) {
                                        $params['servers'] = [ 
$params['server'] ];
-                                       unset( $param['server'] );
+                                       unset( $params['server'] );
                                }
                                // In the past it was not required to set 
'dbDirectory' in $wgObjectCaches
                                if ( isset( $params['servers'] ) ) {
@@ -217,7 +223,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 +276,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 +321,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: merged
Gerrit-Change-Id: I36108a865273b9c209145828e5e1216b545ef431
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to