diff options
author | Bartosz DziewoĆski <dziewonski@fastmail.fm> | 2025-03-19 04:36:04 +0100 |
---|---|---|
committer | Krinkle <krinkle@fastmail.com> | 2025-03-21 23:32:41 +0000 |
commit | 6cddec0254be56d759cc0825b785d834a6d26a2b (patch) | |
tree | cde0812a82c4e8ae7560b8fd3a187aeacb5cc946 /tests | |
parent | 0582c2c6988c634a54f8b16366455c02c0cb3e89 (diff) | |
download | mediawikicore-6cddec0254be56d759cc0825b785d834a6d26a2b.tar.gz mediawikicore-6cddec0254be56d759cc0825b785d834a6d26a2b.zip |
exception: Remove 'exception-json' logging channel
It provided structured exception data in a custom machine-readable
format. Since MediaWiki 1.26, structured exception data conforming to
the PSR-3 logging standard is also available on the 'exception' log
channel, and nobody uses 'exception-json' anymore. But the fact that
it exists and logs errors by default means that it has to be disabled,
and clutters configs, for example:
https://gerrit.wikimedia.org/g/operations/mediawiki-config/+/c0e5c7f71d70de5749f6770abcbbb7e57032bd29/wmf-config/InitialiseSettings.php#2225
https://gerrit.wikimedia.org/g/mediawiki/vagrant/+/c96e609b6ff6a73a412d3fd0a4291259eee026f6/puppet/modules/role/templates/psr3/settings.php.erb#57
Historical context:
* Iacda90fb401f6a45ed1ac1a991e088: Add "exception-json" channel, 2013.
* Ia7ba355d5925a6268ffa321ffc13cc: Add "error-json" channel, 2015.
* I71499d895582bdea033a2516c902e2: Convert "exception" to PSR-3, 2015.
* I782c96dac1181d12267fa610345e87: WMF disables "exception-json", 2017.
* I7a6e6fa52a47a29ec04411a6c8b05e: Remove "error-json" channel, 2024.
The custom data format has been reused for formatting exceptions in
the REST API, so keep getStructuredExceptionData() and rescue the tests.
Bug: T193472
Change-Id: If730618e5371a467cb76db239916b6bbe42512e3
Diffstat (limited to 'tests')
-rw-r--r-- | tests/phpunit/includes/exception/MWExceptionTest.php | 20 | ||||
-rw-r--r-- | tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php | 30 |
2 files changed, 12 insertions, 38 deletions
diff --git a/tests/phpunit/includes/exception/MWExceptionTest.php b/tests/phpunit/includes/exception/MWExceptionTest.php index 5c3564479dd7..8e4bd94e8a5e 100644 --- a/tests/phpunit/includes/exception/MWExceptionTest.php +++ b/tests/phpunit/includes/exception/MWExceptionTest.php @@ -24,26 +24,6 @@ class MWExceptionTest extends MediaWikiIntegrationTestCase { } /** - * Verify the exception classes are JSON serializabe. - * - * @dataProvider provideExceptionClasses - */ - public function testJsonSerializeExceptions( $exception_class ) { - $json = MWExceptionHandler::jsonSerializeException( - new $exception_class() - ); - $this->assertIsString( $json, - "The $exception_class exception should be JSON serializable, got false." ); - } - - public static function provideExceptionClasses() { - return [ - [ Exception::class ], - [ MWException::class ], - ]; - } - - /** * @covers \MWException::report */ public function testReport() { diff --git a/tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php b/tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php index 8fb9dfc07b60..d5f57451fa61 100644 --- a/tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php +++ b/tests/phpunit/unit/includes/exception/MWExceptionHandlerTest.php @@ -133,23 +133,21 @@ TEXT; } /** - * @dataProvider provideJsonSerializedKeys + * @dataProvider provideGetStructuredExceptionDataKeys * @param string $expectedKeyType Type expected as returned by get_debug_type() * @param string $exClass An exception class (ie: Exception, MWException) * @param string $key Name of the key to validate in the serialized JSON */ - public function testJsonserializeexceptionKeys( $expectedKeyType, $exClass, $key ) { - $json = json_decode( - MWExceptionHandler::jsonSerializeException( new $exClass() ) - ); - $this->assertObjectHasProperty( $key, $json ); - $this->assertSame( $expectedKeyType, get_debug_type( $json->$key ), "Type of the '$key' key" ); + public function testGetStructuredExceptionDataKeys( $expectedKeyType, $exClass, $key ) { + $data = MWExceptionHandler::getStructuredExceptionData( new $exClass() ); + $this->assertArrayHasKey( $key, $data ); + $this->assertSame( $expectedKeyType, get_debug_type( $data[$key] ), "Type of the '$key' key" ); } /** * Each case provides: [ type, exception class, key name ] */ - public static function provideJsonSerializedKeys() { + public static function provideGetStructuredExceptionDataKeys() { foreach ( [ Exception::class, MWException::class ] as $exClass ) { yield [ 'string', $exClass, 'id' ]; yield [ 'string', $exClass, 'file' ]; @@ -165,26 +163,22 @@ TEXT; * Given wgLogExceptionBacktrace is true * then serialized exception must have a backtrace */ - public function testJsonserializeexceptionBacktracingEnabled() { + public function testGetStructuredExceptionDataBacktracingEnabled() { TestingAccessWrapper::newFromClass( MWExceptionHandler::class ) ->logExceptionBacktrace = true; - $json = json_decode( - MWExceptionHandler::jsonSerializeException( new Exception() ) - ); - $this->assertObjectHasProperty( 'backtrace', $json ); + $data = MWExceptionHandler::getStructuredExceptionData( new Exception() ); + $this->assertArrayHasKey( 'backtrace', $data ); } /** * Given wgLogExceptionBacktrace is false * then serialized exception must not have a backtrace */ - public function testJsonserializeexceptionBacktracingDisabled() { + public function testGetStructuredExceptionDataBacktracingDisabled() { TestingAccessWrapper::newFromClass( MWExceptionHandler::class ) ->logExceptionBacktrace = false; - $json = json_decode( - MWExceptionHandler::jsonSerializeException( new Exception() ) - ); - $this->assertObjectNotHasProperty( 'backtrace', $json ); + $data = MWExceptionHandler::getStructuredExceptionData( new Exception() ); + $this->assertArrayNotHasKey( 'backtrace', $data ); } /** |