Page MenuHomePhabricator

/w/rest.php/reportincident/v0/report InvalidArgumentException: Scalar parameter must be a string, number, or MessageValue; got NULL
Closed, ResolvedPublicBUG REPORT

Description

What is the problem?

I can get the reportincident API endpoint (rest.php/reportincident/v0/report/) to return this error:

[error] [95ddb8d85aff8e32cb752e77] /w/rest.php/reportincident/v0/report   PHP Warning: Trying to access array offset on value of type null
#0 /var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php(88): MWExceptionHandler::handleError()
#1 /var/www/html/w/includes/Rest/SimpleHandler.php(38): MediaWiki\Extension\ReportIncident\Api\Rest\Handler\ReportHandler->run()
#2 /var/www/html/w/includes/Rest/Router.php(517): MediaWiki\Rest\SimpleHandler->execute()
#3 /var/www/html/w/includes/Rest/Router.php(422): MediaWiki\Rest\Router->executeHandler()
#4 /var/www/html/w/includes/Rest/EntryPoint.php(195): MediaWiki\Rest\Router->execute()
#5 /var/www/html/w/includes/Rest/EntryPoint.php(135): MediaWiki\Rest\EntryPoint->execute()
#6 /var/www/html/w/rest.php(31): MediaWiki\Rest\EntryPoint::main()
#7 {main}
....
[exception] [95ddb8d85aff8e32cb752e77] /w/rest.php/reportincident/v0/report   InvalidArgumentException: Scalar parameter must be a string, number, or MessageValue; got NULL
#0 /var/www/html/w/includes/libs/Message/MessageValue.php(77): Wikimedia\Message\ScalarParam->__construct()
#1 /var/www/html/w/includes/libs/Message/MessageValue.php(35): Wikimedia\Message\MessageValue->params()
#2 /var/www/html/w/extensions/ReportIncident/src/Api/Rest/Handler/ReportHandler.php(92): Wikimedia\Message\MessageValue->__construct()
#3 /var/www/html/w/includes/Rest/SimpleHandler.php(38): MediaWiki\Extension\ReportIncident\Api\Rest\Handler\ReportHandler->run()
#4 /var/www/html/w/includes/Rest/Router.php(517): MediaWiki\Rest\SimpleHandler->execute()
#5 /var/www/html/w/includes/Rest/Router.php(422): MediaWiki\Rest\Router->executeHandler()
#6 /var/www/html/w/includes/Rest/EntryPoint.php(195): MediaWiki\Rest\Router->execute()
#7 /var/www/html/w/includes/Rest/EntryPoint.php(135): MediaWiki\Rest\EntryPoint->execute()
#8 /var/www/html/w/rest.php(31): MediaWiki\Rest\EntryPoint::main()
#9 {main}

This happens when a logged-in user with permission to submit the report incident form sends in a request that uses form data.

Steps to reproduce problem
  1. Setup a wiki with ReportIncident installed
  2. Login to an account that has not submitted a incident report within the last day.
  3. Run this command in your browser console (this performs a request to the API with form data) after replacing http://localhost:8080 with the domain name of the wiki you are using:
await fetch("http://localhost:8080/w/rest.php/reportincident/v0/report", {
    "headers": {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0",
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Language": "en-GB,en;q=0.5",
        "Content-Type": "application/x-www-form-urlencoded",
        "X-Requested-With": "XMLHttpRequest",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "Pragma": "no-cache",
        "Cache-Control": "no-cache"
    },
    "referrer": "http://localhost:8080/wiki/User_talk:Dreamyjazz",
    "body": "foobar",
    "method": "POST"
});

What happens
I get a 500 server error as shown above

What should happen
A 4XX error (an error code starting with a 4) should be returned.

Environment

Wiki(s): 1.42.0-alpha (72f7b7a) 12:57, 18 October 2023. ReportIncident (b42b772) 12:22, 18 October 2023.

Event Timeline

Restricted Application added a subscriber: Aklapper. ยท View Herald Transcript

Change 964565 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/ReportIncident@master] Suggest usernames for the reported username field

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

Change 964565 merged by jenkins-bot:

[mediawiki/extensions/ReportIncident@master] Suggest usernames for the reported username field

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

I would suggest following the steps to reproduce for QA. For QA on patchdemo and/or beta wikis, you will need to replace the http://localhost:8080 with https://patchdemo.wmflabs.org/wikis/X where the X is a hexadecimal string or https://ko.wikipedia.beta.wmflabs.org.

@Dreamy_Jazz An error code starting with a 4 can be seen in the screenshot below. I did have a question regarding what you mentioned above which I slacked message you. Thanks!

Status: โœ… PASS
Environment: Local: 1.42.0-alpha (23e0708)13:52, 19 October 2023. ReportIncident: (404454b) 13:13, 19 October 2023
OS: macOS Sonoma 14.0
Browser: Chrome 117
Skins. N/A
Device: MBA M2
Emulated Device:: n/a
Test Links:
http://localhost:8080/wiki/User_talk:Testuserthree

โœ…AC1: https://phabricator.wikimedia.org/T349226

2023-10-19_13-41-33.png (1ร—3 px, 381 KB)

Test wiki created on Patch demo by DJacksonA using patch(es) linked to this task:
https://patchdemo.wmflabs.org/wikis/0ca007bc0f/w

Test wiki on Patch demo by DJacksonA using patch(es) linked to this task was deleted:

https://patchdemo.wmflabs.org/wikis/0ca007bc0f/w/