Include preg_last_error() in error message when preg_* fails
authorGergő Tisza <tgr.huwiki@gmail.com>
Thu, 29 Oct 2015 20:49:11 +0000 (13:49 -0700)
committerGergő Tisza <tgr.huwiki@gmail.com>
Thu, 29 Oct 2015 21:00:37 +0000 (14:00 -0700)
Bug: T115514
Bug: T117066
Change-Id: I1d13f8542a4cf11c8e87cd4f6a983fa852dfdf1e

includes/MagicWord.php

index 424735e..17c7cd4 100644 (file)
@@ -954,7 +954,8 @@ class MagicWordArray {
                        $matches = array();
                        $matched = preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
                        if ( $matched === false ) {
-                               throw new Exception( __METHOD__ . ': preg_match_all returned false' );
+                               throw new Exception( __METHOD__ . ': preg_match_all returned false with error code '
+                                       . preg_last_error() );
                        }
                        if ( $matched ) {
                                foreach ( $matches as $m ) {
@@ -966,7 +967,8 @@ class MagicWordArray {
                        if ( $replaced !== null ) {
                                $text = $replaced;
                        } else {
-                               throw new Exception( __METHOD__ . ': preg_replace returned null' );
+                               throw new Exception( __METHOD__ . ': preg_replace returned null with error code '
+                                       . preg_last_error() );
                        }
                }
                return $found;