Page MenuHomePhabricator

mediawiki.Api should show warnings returned by the API
Open, Needs TriagePublicFeature

Description

Feature summary (what you would like to be able to do and where):
mw.Api() should show warnings returned by the Action API, e.g. by logging them via console.warn().

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
As a gadget or user script developer, I want to know when I use deprecated API usage patterns. When the API returns warnings, I expect mw.Api() to show them.

Benefits (why should this be implemented?):
Helps to discover user scripts and gadgets that need to be fixed.

Example:

await new mw.Api().get( { action: 'query', prop: 'revisions', rvprop: 'content', pageids: 1 } )

The API returns a warning (about the usage of rvprop=content without rvslots=), but it’s only visible if you look at the response yourself.

By contrast:

await new mw.Api().get( { action: 'edit' } )

The API returns an error, which mw.Api reports as a promise rejection. Users don’t have to check response.errors ?? [ response.error ] themselves.

Event Timeline

Note that not all warnings are as straightforward as the one about rvslots=. For example, the truncatedresult warning can be handled by well-written code (follow continuation until batchcomplete is seen), and such code can’t reasonably prevent the warning from being emitted before it handles it. My own m3api library has support for suppressing this warning (dropTruncatedResultWarning request option, enabled by default in requestAndContinueReducingBatch()), but I think that might be overkill for mw.Api()… maybe it’s just okay if the warning is occasionally logged to the browser console.

I’m not sure what this task has to do with T392595 given that that task seems to be specific to the REST API…