if ( $tag === 'error' ) {
// In BC mode, only one error
- $value = [
- 'code' => $msg->getApiCode(),
- 'info' => $value,
- ] + $msg->getApiData();
- $this->result->addValue( null, 'error', $value,
- ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+ $existingError = $this->result->getResultData( [ 'error' ] );
+ if ( !is_array( $existingError ) ||
+ !isset( $existingError['code'] ) || !isset( $existingError['info'] )
+ ) {
+ $value = [
+ 'code' => $msg->getApiCode(),
+ 'info' => $value,
+ ] + $msg->getApiData();
+ $this->result->addValue( null, 'error', $value,
+ ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+ }
} else {
if ( $modulePath === null ) {
$moduleName = 'unknown';
$formatter->addMessagesFromStatus( 'status', $status );
$this->assertSame( [
'error' => [
- 'code' => 'parentheses',
- 'info' => $parensPlain,
+ 'code' => 'mainpage',
+ 'info' => $mainpagePlain,
],
'warnings' => [
'status' => [
$formatter->arrayFromStatus( $status, 'warning' ),
'arrayFromStatus test for warning'
);
+
+ $result->reset();
+ $result->addValue( null, 'error', [ 'bogus' ] );
+ $formatter->addError( 'err', 'mainpage' );
+ $this->assertSame( [
+ 'error' => [
+ 'code' => 'mainpage',
+ 'info' => $mainpagePlain,
+ ],
+ ApiResult::META_TYPE => 'assoc',
+ ], $result->getResultData(), 'Overwrites bogus "error" value with real error' );
}
/**