user: Allow "CAS update failed" exceptions to be normalised
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 12 Sep 2018 17:33:34 +0000 (18:33 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 12 Sep 2018 17:33:34 +0000 (18:33 +0100)
Take the user_id variable out of the exception message.
To compensate and still allow one to correlate patterns relating
to a specific user (e.g. a bot), add a warning message that
still contains the variable via context. This way that warning
will also be normalised/grouped, but with the extra context.

This is separate because exceptions do not currently support
context placeholders.

Bug: T202149
Change-Id: Ic0c25f66f23fdc65821da12f949c6224bc03f9b3

includes/user/User.php

index 7bebe80..d61c29d 100644 (file)
@@ -27,6 +27,7 @@ use MediaWiki\Auth\AuthManager;
 use MediaWiki\Auth\AuthenticationResponse;
 use MediaWiki\Auth\AuthenticationRequest;
 use MediaWiki\User\UserIdentity;
+use MediaWiki\Logger\LoggerFactory;
 use Wikimedia\IPSet;
 use Wikimedia\ScopedCallback;
 use Wikimedia\Rdbms\Database;
@@ -4208,9 +4209,12 @@ class User implements IDBAccessObject, UserIdentity {
                                $this->clearSharedCache( 'refresh' );
                                // User was changed in the meantime or loaded with stale data
                                $from = ( $this->queryFlagsUsed & self::READ_LATEST ) ? 'master' : 'replica';
-                               throw new MWException(
-                                       "CAS update failed on user_touched for user ID '{$this->mId}' (read from $from);" .
-                                       " the version of the user to be saved is older than the current version."
+                               LoggerFactory::getInstance( 'preferences' )->warning(
+                                       "CAS update failed on user_touched for user ID '{user_id}' ({db_flag} read)",
+                                       [ 'user_id' => $this->mId, 'db_flag' => $from ]
+                               );
+                               throw new MWException( "CAS update failed on user_touched. " .
+                                       "The version of the user to be saved is older than the current version."
                                );
                        }