jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/358352 )

Change subject: Catch SparqlHelperException in DelegatingConstraintChecker
......................................................................


Catch SparqlHelperException in DelegatingConstraintChecker

TypeChecker and ValueTypeChecker previously did not correctly handle the
possibility of a SparqlHelperException (introduced in Ie7c67a88a1).
Instead of copying the code from the SPARQL versions of the checkers,
the exception handling is moved up to DelegatingConstraintChecker, which
already catches another exception type (ConstraintParameterException).

Also adds missing @throws documentation tags to many functions.

Change-Id: I4b90142a8dcbf86d62b5f50cb315fbe9993f3740
---
M includes/ConstraintCheck/Checker/TypeSparqlChecker.php
M includes/ConstraintCheck/Checker/ValueTypeSparqlChecker.php
M includes/ConstraintCheck/ConstraintChecker.php
M includes/ConstraintCheck/DelegatingConstraintChecker.php
M includes/ConstraintCheck/Helper/SparqlHelper.php
M includes/ConstraintCheck/Helper/TypeCheckerHelper.php
6 files changed, 31 insertions(+), 20 deletions(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified
  Thiemo Mättig (WMDE): Looks good to me, but someone else must approve



diff --git a/includes/ConstraintCheck/Checker/TypeSparqlChecker.php 
b/includes/ConstraintCheck/Checker/TypeSparqlChecker.php
index 7c1ab43..89b673d 100644
--- a/includes/ConstraintCheck/Checker/TypeSparqlChecker.php
+++ b/includes/ConstraintCheck/Checker/TypeSparqlChecker.php
@@ -94,17 +94,12 @@
                }
 
                if ( $this->sparqlHelper !== null ) {
-                       try {
-                               if ( $this->sparqlHelper->hasType( 
$entity->getId()->getSerialization(), $classes, $withInstance ) ) {
-                                       $message = '';
-                                       $status = 
CheckResult::STATUS_COMPLIANCE;
-                               } else {
-                                       $message = wfMessage( 
"wbqc-violation-message-sparql-type" )->escaped();
-                                       $status = CheckResult::STATUS_VIOLATION;
-                               }
-                       } catch ( SparqlHelperException $e ) {
+                       if ( $this->sparqlHelper->hasType( 
$entity->getId()->getSerialization(), $classes, $withInstance ) ) {
+                               $message = '';
+                               $status = CheckResult::STATUS_COMPLIANCE;
+                       } else {
+                               $message = wfMessage( 
"wbqc-violation-message-sparql-type" )->escaped();
                                $status = CheckResult::STATUS_VIOLATION;
-                               $message = wfMessage( 
'wbqc-violation-message-sparql-error' )->escaped();
                        }
                } else {
                        $status = CheckResult::STATUS_TODO;
diff --git a/includes/ConstraintCheck/Checker/ValueTypeSparqlChecker.php 
b/includes/ConstraintCheck/Checker/ValueTypeSparqlChecker.php
index 0544c77..fbb8de9 100644
--- a/includes/ConstraintCheck/Checker/ValueTypeSparqlChecker.php
+++ b/includes/ConstraintCheck/Checker/ValueTypeSparqlChecker.php
@@ -127,17 +127,12 @@
                }
 
                if ( $this->sparqlHelper !== null ) {
-                       try {
-                               if ( $this->sparqlHelper->hasType( 
$dataValue->getEntityId()->getSerialization(), $classes, $withInstance ) ) {
-                                       $message = '';
-                                       $status = 
CheckResult::STATUS_COMPLIANCE;
-                               } else {
-                                       $message = wfMessage( 
"wbqc-violation-message-sparql-value-type" )->escaped();
-                                       $status = CheckResult::STATUS_VIOLATION;
-                               }
-                       } catch ( SparqlHelperException $e ) {
+                       if ( $this->sparqlHelper->hasType( 
$dataValue->getEntityId()->getSerialization(), $classes, $withInstance ) ) {
+                               $message = '';
+                               $status = CheckResult::STATUS_COMPLIANCE;
+                       } else {
+                               $message = wfMessage( 
"wbqc-violation-message-sparql-value-type" )->escaped();
                                $status = CheckResult::STATUS_VIOLATION;
-                               $message = wfMessage( 
'wbqc-violation-message-sparql-error' )->escaped();
                        }
                } else {
                        $status = CheckResult::STATUS_TODO;
diff --git a/includes/ConstraintCheck/ConstraintChecker.php 
b/includes/ConstraintCheck/ConstraintChecker.php
index 59fd0dd..944b155 100644
--- a/includes/ConstraintCheck/ConstraintChecker.php
+++ b/includes/ConstraintCheck/ConstraintChecker.php
@@ -6,6 +6,7 @@
 use Wikibase\DataModel\Statement\Statement;
 use Wikibase\DataModel\Statement\StatementListProvider;
 use WikibaseQuality\ConstraintReport\Constraint;
+use 
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\SparqlHelperException;
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
 
 interface ConstraintChecker {
@@ -16,6 +17,8 @@
         * @param EntityDocument|StatementListProvider $entity
         *
         * @return CheckResult
+        *
+        * @throws SparqlHelperException if the checker uses SPARQL and the 
query times out or some other error occurs
         */
        public function checkConstraint( Statement $statement, Constraint 
$constraint, EntityDocument $entity );
 
diff --git a/includes/ConstraintCheck/DelegatingConstraintChecker.php 
b/includes/ConstraintCheck/DelegatingConstraintChecker.php
index c516a32..2c8daa2 100644
--- a/includes/ConstraintCheck/DelegatingConstraintChecker.php
+++ b/includes/ConstraintCheck/DelegatingConstraintChecker.php
@@ -249,6 +249,16 @@
                                        CheckResult::STATUS_VIOLATION,
                                        $e->getMessage()
                                );
+                       } catch ( SparqlHelperException $e ) {
+                               $result = new CheckResult(
+                                       $entity->getId(),
+                                       $statement,
+                                       $constraint->getConstraintTypeQid(),
+                                       $constraint->getConstraintId(),
+                                       [],
+                                       CheckResult::STATUS_VIOLATION,
+                                       wfMessage( 
'wbqc-violation-message-sparql-error' )->escaped()
+                               );
                        }
                        $statsd->timing(
                                'wikibase.quality.constraints.check.timing.' . 
$constraint->getConstraintTypeQid(),
diff --git a/includes/ConstraintCheck/Helper/SparqlHelper.php 
b/includes/ConstraintCheck/Helper/SparqlHelper.php
index ff43f8a..1b62e87 100644
--- a/includes/ConstraintCheck/Helper/SparqlHelper.php
+++ b/includes/ConstraintCheck/Helper/SparqlHelper.php
@@ -62,6 +62,7 @@
         * @param string[] $classes entity ID serializations of the expected 
types
         * @param boolean $withInstance true for “instance” relation, false for 
“subclass” relation
         * @return boolean
+        * @throws SparqlHelperException if the query times out or some other 
error occurs
         */
        public function hasType( $id, array $classes, $withInstance ) {
                $instanceOfId = $this->config->get( 
'WBQualityConstraintsInstanceOfId' );
@@ -97,6 +98,7 @@
        /**
         * @param Statement $statement
         * @return (EntityId|null)[]
+        * @throws SparqlHelperException if the query times out or some other 
error occurs
         */
        public function findEntitiesWithSameStatement( Statement $statement ) {
                $pid = $statement->getPropertyId()->serialize();
@@ -141,6 +143,8 @@
         * @param string $query The query, unencoded (plain string).
         *
         * @return array The returned JSON data (you typically iterate over 
["results"]["bindings"]).
+        *
+        * @throws SparqlHelperException if the query times out or some other 
error occurs
         */
        public function runQuery( $query ) {
 
diff --git a/includes/ConstraintCheck/Helper/TypeCheckerHelper.php 
b/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
index 1136a0f..ff2ba1f 100644
--- a/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
+++ b/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
@@ -74,6 +74,8 @@
         * @param int &$entitiesChecked
         *
         * @return bool
+        *
+        * @throws SparqlHelperException if SPARQL is used and the query times 
out or some other error occurs
         */
        public function isSubclassOf( EntityId $comparativeClass, array 
$classesToCheck, &$entitiesChecked = 0 ) {
                $maxEntities = $this->config->get( 
'WBQualityConstraintsTypeCheckMaxEntities' );
@@ -131,6 +133,8 @@
         * @param string[] $classesToCheck
         *
         * @return bool
+        *
+        * @throws SparqlHelperException if SPARQL is used and the query times 
out or some other error occurs
         */
        public function hasClassInRelation( StatementList $statements, 
$relationId, array $classesToCheck ) {
                /** @var Statement $statement */

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4b90142a8dcbf86d62b5f50cb315fbe9993f3740
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to