Thiemo Mättig (WMDE) has uploaded a new change for review.

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

Change subject: Replace unclear "oops" and "can't happen" with empty 
LogicExceptions
......................................................................

Replace unclear "oops" and "can't happen" with empty LogicExceptions

Unfortunately the methods ApiBase::die...() hide the exceptions that
are actually thrown. PhpStorm and other tools don't understand this
and show an error. That's why some kind of return or throw is needed
even if we are sure the line will never be executed.

Exceptions with "oops" or "can't happen" messages already caused
confusion in other patches. Therefor I suggest to use empty
LogicExceptions.

Change-Id: Ie6acf74fdb63b701054fd300bfb3ff3e4afc08c1
---
M repo/includes/api/ApiWikibase.php
M repo/includes/api/FormatSnakValue.php
M repo/includes/api/ModifyEntity.php
M repo/includes/api/SetClaim.php
4 files changed, 32 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/11/122411/1

diff --git a/repo/includes/api/ApiWikibase.php 
b/repo/includes/api/ApiWikibase.php
index 63deffe..6b0b6c1 100644
--- a/repo/includes/api/ApiWikibase.php
+++ b/repo/includes/api/ApiWikibase.php
@@ -2,17 +2,18 @@
 
 namespace Wikibase\Api;
 
+use ApiBase;
 use ApiMain;
-use Exception;
 use LogicException;
 use Message;
 use MessageCache;
-use User;
 use Status;
-use ApiBase;
+use UsageException;
+use User;
 use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdParser;
+use Wikibase\EditEntity;
 use Wikibase\EntityFactory;
 use Wikibase\EntityPermissionChecker;
 use Wikibase\EntityRevision;
@@ -20,7 +21,6 @@
 use Wikibase\EntityTitleLookup;
 use Wikibase\Lib\PropertyDataTypeLookup;
 use Wikibase\Lib\Serializers\SerializerFactory;
-use Wikibase\EditEntity;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\StorageException;
 use Wikibase\store\EntityStore;
@@ -275,8 +275,8 @@
         * @param EntityId $entityId : the title of the page to load the 
revision for
         * @param int $revId : the revision to load. If not given, the current 
revision will be loaded.
         *
-        * @throws \Exception
-        * @throws \UsageException
+        * @throws UsageException
+        * @throws LogicException
         * @return EntityRevision
         */
        protected function loadEntityRevision(
@@ -298,7 +298,8 @@
                        $this->dieUsage( "Revision $revId not found: " . 
$ex->getMessage(), 'nosuchrevid' );
                }
 
-               throw new Exception( 'can\'t happen' );
+               // The only reason for this is that ApiBase::dieUsage hides the 
actual UsageException
+               throw new LogicException();
        }
 
        /**
diff --git a/repo/includes/api/FormatSnakValue.php 
b/repo/includes/api/FormatSnakValue.php
index 5ce7230..4b110d8 100644
--- a/repo/includes/api/FormatSnakValue.php
+++ b/repo/includes/api/FormatSnakValue.php
@@ -8,6 +8,7 @@
 use DataValues\IllegalValueException;
 use DataValues\StringValue;
 use LogicException;
+use UsageException;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatter;
 use Wikibase\Lib\OutputFormatValueFormatterFactory;
@@ -109,6 +110,8 @@
         *
         * @param string $json A JSON-encoded DataValue
         *
+        * @throws UsageException
+        * @throws LogicException
         * @return DataValue
         */
        protected function decodeDataValue( $json ) {
@@ -124,6 +127,9 @@
                } catch ( IllegalValueException $ex ) {
                        $this->dieUsage( $ex->getMessage(), 'baddatavalue' );
                }
+
+               // The only reason for this is that ApiBase::dieUsage hides the 
actual UsageException
+               throw new LogicException();
        }
 
        /**
diff --git a/repo/includes/api/ModifyEntity.php 
b/repo/includes/api/ModifyEntity.php
index 767b0e7..ee1b73c 100644
--- a/repo/includes/api/ModifyEntity.php
+++ b/repo/includes/api/ModifyEntity.php
@@ -2,10 +2,11 @@
 
 namespace Wikibase\Api;
 
+use ApiBase;
 use ApiMain;
+use LogicException;
 use SiteSQLStore;
 use Status;
-use ApiBase;
 use UsageException;
 use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\Entity\EntityId;
@@ -120,6 +121,7 @@
         * @param string $id
         *
         * @throws UsageException
+        * @throws LogicException
         * @return EntityId
         */
        protected function getEntityIdFromString( $id ) {
@@ -128,6 +130,9 @@
                } catch ( EntityIdParsingException $ex ) {
                        $this->dieUsage( $ex->getMessage(), 'no-such-entity-id' 
);
                }
+
+               // The only reason for this is that ApiBase::dieUsage hides the 
actual UsageException
+               throw new LogicException();
        }
 
        /**
diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php
index 6b78f89..a2c3a01 100644
--- a/repo/includes/api/SetClaim.php
+++ b/repo/includes/api/SetClaim.php
@@ -5,11 +5,13 @@
 use ApiBase;
 use ApiMain;
 use DataValues\IllegalValueException;
-use InvalidArgumentException;
-use OutOfBoundsException;
 use Diff\Comparer\ComparableComparer;
 use Diff\OrderedListDiffer;
 use FormatJson;
+use InvalidArgumentException;
+use LogicException;
+use OutOfBoundsException;
+use UsageException;
 use Wikibase\ChangeOp\ChangeOpClaim;
 use Wikibase\ChangeOp\ChangeOpException;
 use Wikibase\ClaimDiffer;
@@ -118,7 +120,12 @@
 
        /**
         * @since 0.4
+        *
         * @param array $params
+        *
+        * @throws IllegalValueException
+        * @throws UsageException
+        * @throws LogicException
         * @return Claim
         */
        protected function getClaimFromParams( array $params ) {
@@ -140,6 +147,9 @@
                } catch( OutOfBoundsException $outOfBoundsException ) {
                        $this->dieUsage( 'Failed to get claim from claim 
Serialization ' . $outOfBoundsException->getMessage(), 'invalid-claim' );
                }
+
+               // The only reason for this is that ApiBase::dieUsage hides the 
actual UsageException
+               throw new LogicException();
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6acf74fdb63b701054fd300bfb3ff3e4afc08c1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

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

Reply via email to