r87449 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87448‎ | r87449 | r87450 >
Date:20:31, 4 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
implemented correct handling of fatal paramater handling errors
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php
@@ -152,8 +152,15 @@
153153 $this->hasTemplates = false;
154154
155155 if ( $this->useValidator ) {
156 - // TODO: retain behaviour of base readParameters
157 - $this->handleParameters( $this->handleRawParameters( $params ), $outputmode );
 156+ $paramValidationResult = $this->handleRawParameters( $params );
 157+
 158+ if ( is_array( $paramValidationResult ) ) {
 159+ $this->handleParameters( $paramValidationResult, $outputmode );
 160+ }
 161+ else {
 162+ $this->addError( $paramValidationResult );
 163+ return $this->getErrorString( $results );
 164+ }
158165 }
159166 else {
160167 $this->readParameters( $params, $outputmode );
@@ -277,25 +284,26 @@
278285
279286 /**
280287 * Handles the user-provided parameters and returns the processes key-value pairs.
 288+ * If there is a fatal error, a string with the error message will be returned intsead.
281289 *
282290 * @since 1.6
283291 *
284292 * @param array $keyValuePairs
285293 *
286 - * @return array
 294+ * @return array or string
287295 */
288296 protected function handleRawParameters( array $keyValuePairs ) {
289297 $validator = new Validator();
290298 $validator->setParameters( $keyValuePairs, $this->getParameters() );
291299 $validator->validateParameters();
 300+ $fatalError = $validator->hasFatalError();
292301
293 - if ( $validator->hasFatalError() ) {
294 - // TODO
295 - throw new Exception( 'Validator: fatal param validation error' );
 302+ if ( $fatalError === false ) {
 303+ $this->mErrors = $validator->getErrorMessages();
 304+ return $validator->getParameterValues();
296305 }
297306 else {
298 - $this->mErrors = $validator->getErrorMessages();
299 - return $validator->getParameterValues();
 307+ return $fatalError->getMessage();
300308 }
301309 }
302310

Status & tagging log