UsageException: Validate that $codestr is a non-empty string
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 27 Jun 2016 23:31:56 +0000 (19:31 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 27 Jun 2016 23:31:56 +0000 (19:31 -0400)
Current theory on T138585 is that something is passing in false, so
let's throw an InvalidArgumentException that should log a backtrace for
us.

Bug: T138585
Change-Id: Iba0dad424c56340b8bc73322bb1a7ae6d4de314a

includes/api/ApiMain.php

index ce9587f..c8601a0 100644 (file)
@@ -1901,6 +1901,14 @@ class UsageException extends MWException {
                parent::__construct( $message, $code );
                $this->mCodestr = $codestr;
                $this->mExtraData = $extradata;
+
+               // This should never happen, so throw an exception about it that will
+               // hopefully get logged with a backtrace (T138585)
+               if ( !is_string( $codestr ) || $codestr === '' ) {
+                       throw new InvalidArgumentException( 'Invalid $codestr, was ' .
+                               ( $codestr === '' ? 'empty string' : gettype( $codestr ) )
+                       );
+               }
        }
 
        /**