Hashar has uploaded a new change for review.

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


Change subject: MWExceptionHandler::formatArgumentsInCall
......................................................................

MWExceptionHandler::formatArgumentsInCall

When logging exception to text, we were internally formatting the
arguments and emitting the resulting string. This patch extract the
formatting code so other exception logging method can reuse the
abstracted array.

An example is https://gerrit.wikimedia.org/r/#/c/76304 which would log
exceptions as JSON and would need to reuse the array to encode it to
JSON.

Change-Id: I3d570a6385f96a606e1af53c50faa03b9ebacd38
---
M includes/Exception.php
1 file changed, 29 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/34/92334/1

diff --git a/includes/Exception.php b/includes/Exception.php
index a91f865..227b262 100644
--- a/includes/Exception.php
+++ b/includes/Exception.php
@@ -722,25 +722,39 @@
                        } else {
                                $finalExceptionText .= $call['function'];
                        }
-                       $args = array();
-                       if ( isset( $call['args'] ) ) {
-                               foreach ( $call['args'] as $arg ) {
-                                       if ( $arg === $redacted ) {
-                                               $args[] = 'REDACTED';
-                                       } elseif ( is_object( $arg ) ) {
-                                               $args[] = 'Object(' . 
get_class( $arg ) . ')';
-                                       } elseif( is_array( $arg ) ) {
-                                               $args[] = 'Array';
-                                       } else {
-                                               $args[] = var_export( $arg, 
true );
-                                       }
-                               }
-                       }
-                       $finalExceptionText .=  '(' . implode( ', ', $args ) . 
")\n";
+
+                       $args = self::formatArgumentsInCall( $call );
+                       $finalExceptionText .= '(' . implode( ', ', $args ) . 
")\n";
                }
                return $finalExceptionText . '#' . ( $i + 1 ) . ' {main}';
        }
 
+       /**
+        * Format arguments of a stacktrace call.
+        *
+        * @param Array $call A backtrace call entry, should have a 'args' key.
+        * @return Array Formatted arguments. Empty array whenever there is no
+        * arguments.
+        */
+       public static function formatArgumentsInCall( $call ) {
+               if( !isset( $call['args'] ) ) {
+                       return array();
+               }
+
+               $args = array();
+               foreach ( $call['args'] as $arg ) {
+                       if ( $arg === $redacted ) {
+                               $args[] = 'REDACTED';
+                       } elseif ( is_object( $arg ) ) {
+                               $args[] = 'Object(' . get_class( $arg ) . ')';
+                       } elseif( is_array( $arg ) ) {
+                               $args[] = 'Array';
+                       } else {
+                               $args[] = var_export( $arg, true );
+                       }
+               }
+               return $args;
+       }
 
        /**
         * Get the ID for this error.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d570a6385f96a606e1af53c50faa03b9ebacd38
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>

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

Reply via email to