From 65f714e1e679127c4d38a40e7b23da8cee2195d6 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 12 Sep 2018 18:33:34 +0100 Subject: [PATCH] user: Allow "CAS update failed" exceptions to be normalised 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/user/User.php b/includes/user/User.php index 7bebe80715..d61c29d6b4 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -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." ); } -- 2.20.1