+ // Remember existing warnings and errors across the reset
+ $errors = $result->getResultData( [ 'errors' ] );
+ $warnings = $result->getResultData( [ 'warnings' ] );
+ $result->reset();
+ if ( $warnings !== null ) {
+ $result->addValue( null, 'warnings', $warnings, ApiResult::NO_SIZE_CHECK );
+ }
+ if ( $errors !== null ) {
+ $result->addValue( null, 'errors', $errors, ApiResult::NO_SIZE_CHECK );
+
+ // Collect the copied error codes for the return value
+ foreach ( $errors as $error ) {
+ if ( isset( $error['code'] ) ) {
+ $errorCodes[$error['code']] = true;
+ }
+ }
+ }
+
+ // Add errors from the exception
+ $modulePath = $e instanceof ApiUsageException ? $e->getModulePath() : null;
+ foreach ( $this->errorMessagesFromException( $e, 'error' ) as $msg ) {
+ $errorCodes[$msg->getApiCode()] = true;
+ $formatter->addError( $modulePath, $msg );
+ }
+ foreach ( $this->errorMessagesFromException( $e, 'warning' ) as $msg ) {
+ $formatter->addWarning( $modulePath, $msg );
+ }
+
+ // Add additional data. Path depends on whether we're in BC mode or not.
+ // Data depends on the type of exception.
+ if ( $formatter instanceof ApiErrorFormatter_BackCompat ) {
+ $path = [ 'error' ];
+ } else {
+ $path = null;
+ }
+ if ( $e instanceof ApiUsageException || $e instanceof UsageException ) {