Page MenuHomePhabricator

Error message text is treated as message code for some VisualEditor errors
Closed, ResolvedPublic

Description

While I was working on T343848, I noticed that VisualEditor has surprisingly complicated error handling, and I took a look at the error logs to see if any of it is trying to handle errors that no longer occur, using a Superset query like this:

SELECT event.save_failure_type, event.save_failure_message, count(*)
from editattemptstep
where event.action = 'saveFailure'
group by 1, 2
order by 1, 2

Instead, I noticed hundreds of distinct error codes like No_stashed_content_found_for_0_30305d08-3593-11ee-86b3-4cd98faf488b, No_stashed_content_found_for_10071934_521ba810-ffae-11ed-8ab9-1dae4a9f9f9c and so on. It looks like the error message is being incorrectly treated as message code.

I couldn't reproduce that one, but I reproduced a different error that behaves in the same way: https://en.wikipedia.org/wiki/Special:ApiSandbox#action=visualeditoredit&format=json&errorformat=html&paction=diff&page=Scratch&token=4584af8d3d611bd1efe3f6dcbf54ba8064da4fec%2B\&html=<div%20typeof%3D"mw%3ATransclusion"%20data-mw%3D"{}">asdf<%2Fdiv>&formatversion=2

Response:

{
    "errors": [
        {
            "code": "Cannot_serialize_mw_Transclusion_without_data-mw_parts_or_data-parsoid_src",
            "html": "⧼Cannot serialize mw:Transclusion without data-mw.parts or data-parsoid.src⧽",
            "module": "visualeditoredit"
        }
    ],
    "docref": "See https://en.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/&gt; for notice of API deprecations and breaking changes.",
    "servedby": "mw1402"
}

A correct response should have something short as code (it doesn't matter what exactly, as long as it's distinct for each kind of exception, but the same for all exceptions of the same kind – so not generated from the human-readable message), and a human-readable message as html (without the ⧼…⧽ marks, which indicate a missing localisation message).

Event Timeline

Change 948622 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/VisualEditor@master] ApiParsoidTrait: Fix MediaWiki\Rest\HttpException handling

https://gerrit.wikimedia.org/r/948622

Response after:

{
    "errors": [
        {
            "code": "internal_api_error_MediaWiki\\Rest\\HttpException",
            "html": "Cannot serialize mw:Transclusion without data-mw.parts or data-parsoid.src",
            "data": {
                "errorclass": "MediaWiki\\Rest\\HttpException"
            },
            "module": "visualeditoredit"
        }
    ],
    "docref": "See http://localhost:3080/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/&gt; for notice of API deprecations and breaking changes."
}

Change 948622 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] ApiParsoidTrait: Fix MediaWiki\Rest\HttpException handling

https://gerrit.wikimedia.org/r/948622

EAkinloose subscribed.

Validated

Screenshot 2023-09-05 at 20.53.32.png (784×2 px, 167 KB)

Response after:

{
    "errors": [
        {
            "code": "internal_api_error_MediaWiki\\Rest\\HttpException",
            "html": "Cannot serialize mw:Transclusion without data-mw.parts or data-parsoid.src",
            "data": {
                "errorclass": "MediaWiki\\Rest\\HttpException"
            },
            "module": "visualeditoredit"
        }
    ],
    "docref": "See http://localhost:3080/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/&gt; for notice of API deprecations and breaking changes."
}