Before Iae0e2ce3b, the only place in the API that had to deal with
choosing from multiple errors was ApiBase::dieStatus(), which chose the
first one in the Status object. Iae0e2ce3b changed this to choose the
last one instead, which is an unnecessary backwards compatibility break.
While we could make the change in ApiBase::dieStatus(), it's cleaner to
change ApiErrorFormatter_BackCompat's behavior instead since it seems
unlikely anything else was using that code path.
Bug: T155268
Change-Id: Ia06527f8480c3d4a689792ceb8671b0d399ffbe3
if ( $tag === 'error' ) {
// In BC mode, only one error
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';
} else {
if ( $modulePath === null ) {
$moduleName = 'unknown';
$formatter->addMessagesFromStatus( 'status', $status );
$this->assertSame( [
'error' => [
$formatter->addMessagesFromStatus( 'status', $status );
$this->assertSame( [
'error' => [
- 'code' => 'parentheses',
- 'info' => $parensPlain,
+ 'code' => 'mainpage',
+ 'info' => $mainpagePlain,
],
'warnings' => [
'status' => [
],
'warnings' => [
'status' => [
$formatter->arrayFromStatus( $status, 'warning' ),
'arrayFromStatus test for warning'
);
$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' );