Page MenuHomePhabricator

Selenium test failure when deprecation messages happen in API calls: "invalidjson: No valid JSON response"
Closed, DuplicatePublic

Description

For example on this change, but I've seen it elsewhere before: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/AchievementBadges/+/1060793

We have Selenium tests failing with the error message: "invalidjson: No valid JSON response". See Campaign events, betacommons, RelatedArticles, Popups, Minerva, MediaWiki, Math

This is actually caused by PHP deprecation warnings being emitted in api.php (which causes the response to not be valid JSON). If you know where to look, you can find them in the build artifacts: https://integration.wikimedia.org/ci/job/quibble-vendor-mysql-php74-selenium/29880/artifact/log/mw-error.log

2024-08-08 13:09:49 5ed44cfef2b7 wikidb: [17d8b6fb53ab1dc2729c6195] /api.php?format=json   PHP Deprecated: Use of wfGetDB was deprecated in MediaWiki 1.39. [Called from MediaWiki\Extension\AchievementBadges\Achievement::selectLogCount]

This is very difficult to find though. Can we tweak something so that this fails the tests in a more understandable way?

Event Timeline

vaughnwalters renamed this task from Very confusing test failure when deprecation messages happen in API calls: "invalidjson: No valid JSON response" to Selenium test failure when deprecation messages happen in API calls: "invalidjson: No valid JSON response".Aug 11 2025, 9:47 PM

Campaign events extension is failing with the same error Error: invalidjson: No valid JSON response

Error: invalidjson: No valid JSON response
    at /src/node_modules/mwbot/src/index.js:254:31
    at tryCatcher (/src/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/src/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/src/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/src/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/src/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/src/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/src/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/src/node_modules/bluebird/js/release/async.js:102:5)
    at Async.drainQueues [as _onImmediate] (/src/node_modules/bluebird/js/release/async.js:15:14)
    at process.processImmediate (node:internal/timers:483:21)

Also @Daimona noted in T393428#11061918 that the same failure is happening in T382432, which could be causing this as well?

Other extensions that are getting the same error on betacluster selenium-daily runs:
betacommons
RelatedArticles
Popups
Minerva
MediaWiki
Math

Ah, interesting, and yes, that could be a reason. However, I went looking in beta logstash and there are basically no PHP deprecated warnings for the last 2 weeks (except a handful within a very short period, maybe a test or something like that). Still, I suppose it could be any other PHP notice/warning, so I expanded my search. A few things came up like T401643 and some more errors, but I don't know if these are related. For the daily tests, my first guess was that beta just wasn't responding quickly enough.

I checked the code on mwbot and created T401653 for making it more visible what's wrong. If I understand the code correctly the error we get happens if MediaWiki returns HTML instead of JSON (for example an error page). Could it be that our test is blocked (then we get an error page)?

For the specific instance of selenium daily jobs, the cause is an HTTP redirect to the new beta domain: T393428#11077617. I'll make a patch for that task instead. As for this task, I think the action item would be to print additional debug information when the request fails; this is being handled in T401653. I'll close this task as the other has clearer scope.