Page MenuHomePhabricator

Banish the ? Operator in Backend JS
Closed, ResolvedPublic

Description

Description

This operator is useful in TypeScript, where one can reason about objects. It is horribly dangerous in the Wikifunctions backend, because it transparently ignores some REALLY BAD errors.

Desired behavior/Acceptance criteria (returned value, expected error, performance expectations, etc.)

  • eliminate all current uses of the ? operator
  • DO NOT USE THIS OPERATOR IN FUTURE

Remove all the non-applicable tags from the "Tags" field, leave only the tags of the projects/repositories related to this task


Completion checklist

Details

Related Changes in Gerrit:
Related Changes in GitLab:
TitleReferenceAuthorSource BranchDest Branch
execute: Avoid optional chaining to make our code more explicitrepos/abstract-wiki/wikifunctions/function-orchestrator!482jforresterT407791main
Customize query in GitLab

Event Timeline

cmassaro triaged this task as High priority.
Jdforrester-WMF subscribed.

I think we can simply enforce this via "no-unsafe-optional-chaining": "error" in .eslintrc.json.

I think we can simply enforce this via "no-unsafe-optional-chaining": "error" in .eslintrc.json.

Alas, no, that only finds "unsafe" where eslint knows that providing null will explode — which isn't the concern here.

Jdforrester-WMF changed the task status from Open to In Progress.Nov 6 2025, 5:27 PM
Jdforrester-WMF claimed this task.

Beyond the code above, we have two other uses of optional chaining:

In fetchObject.ReferenceResolver:

		Object.defineProperty( this, 'createCustomSpans', {
			get: function () {
				return this.invariants_?.orchestratorConfig?.createCustomSpans ?? null;
			}
		} );

In the boiler-plate in app.js (also in function-evaluator):

	// Default to old service-runner config shape or override with top level
	// TODO: Make config top level in helmchart
	app.conf = {
		// eslint-disable-next-line unicorn/no-useless-fallback-in-spread
		...( conf.services?.[ 0 ]?.conf ?? {} ),
		...conf
	}; // this app's config options

I think those two are OK to leave?

Change #1204583 had a related patch set uploaded (by Jforrester; author: Jforrester):

[operations/deployment-charts@master] wikifunctions: Upgrade orchestrator from 2025-11-04-215809 to 2025-11-08-223341

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

Change #1204583 merged by jenkins-bot:

[operations/deployment-charts@master] wikifunctions: Upgrade orchestrator from 2025-11-04-215809 to 2025-11-08-223341

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