Page MenuHomePhabricator

Make Wikibase error message "Malformed input" more meaningful
Closed, ResolvedPublic

Description

Main components:

  • Action API

User story:
As an API editor
I want to get better feedback on malformed string input
in order to fix my calls.

Problem:
If one is using a malformed string value in an API edit, the users get a "Malformed input" error message. Currently, this error message does not help to find the problem in the string. More assistance would be helpful e.g. for cases of invisible or otherwise indistinguishable characters.

Screenshots:

Screen Shot 2022-03-23 at 6.05.16 PM.png (990×1 px, 405 KB)

Solution:
Improve the error message you get from the API for bad strings. Currently, it’s a generic “malformed value” message, but it should be possible to provide a custom message without too much trouble (ValidatorBuilders::getCommonStringValidators() uses a RegexValidator to check whitespace, which already supports a custom $errorCode as an optional constructor argument). We could also point users to wbparsevalue.

Notes:

Acceptance criteria:

  • Malformed input error message should be more helpful/actionable for the users.

    Open questions:
  • What exactly should the new message be?

    Original:

T47925#7796836 and following

Event Timeline

Sure, feel free to upload a patch on Gerrit. Wikibase/Installation might be useful to set up a local wiki where you can test the behavior.

I would love to see this improved. I often get this generic error when an empty string is passed with a string property. I would also really like to know which property was related to the input error so I don't have to scan through tens of properties to find the anomaly manually.

@gabbyprecious: Hi! This task has been assigned to you a while ago. Could you maybe share an update? Do you still plan to work on this task, or do you need any help?

@gabbyprecious: I am resetting the assignee of this task because there has not been progress lately (please correct me if I am wrong!). Resetting the assignee avoids the impression that somebody is already working on this task. It also allows others to potentially work towards fixing this task. Please claim this task again when you plan to work on it (via Add Action...Assign / Claim in the dropdown menu) - it would be welcome. Thanks for your understanding!

@Lucas_Werkmeister_WMDE I think we can add problematic part of a property as a parameter to the API response? UI can also highlight the issue with the input as well. I don't know if it's a good idea to add it as a parameter though.

Example:

{
    "error": {
        "code": "wikibase-validator-malformed-value",
        "info": "Malformed input: hmm\u00a0"
    },
    "results": [
        {
            "raw": "hmm\u00a0",
            "value": {
                "text": "hmm\u00a0",
                "language": "en"
            },
            "type": "monolingualtext",
            "error": "ValidationError",
            "messages": [
                {
                    "name": "wikibase-validator-malformed-value",
                    "parameters": [
                        "hmm\u00a0",
                        "\u00a0"
                    ],
                    "html": {
                        "*": "Malformed input: hmm "
                    }
                }
            ],
            "validation-errors": [
                "malformed-value"
            ]
        }
    ]
}

I think we should use the existing RegexValidator error reporting, just with a custom error code instead of the default 'malformed-value'.

I think we should use the existing RegexValidator error reporting, just with a custom error code instead of the default 'malformed-value'.

malformed-value is not a wrong error message, but it needs more detail. We already have some additional details in API response, like escaped original string, but I don't know if we add a new custom error code or do something else.

Change 841529 had a related patch set uploaded (by Hasan Akgün (WMDE); author: Hasan Akgün (WMDE)):

[mediawiki/extensions/Wikibase@master] Make Wikibase error message "Malformed input" more meaningful

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

Change 841529 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Make Wikibase error message "Malformed input" more meaningful

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