Page MenuHomePhabricator

Mustache/TemplateParser should emit warning if property doesn't exist
Open, MediumPublic

Description

Issues such as https://gerrit.wikimedia.org/r/#/c/266662/6/includes/specials/SpecialContributions.php shouldn't be possible without leaving something behind in the PHP error log. It's essentially a PHP Notice for undefined variable, except that it's through indirection of TemplateParser (and LightNCandy).

These are still immature and shows in lack of error handling.

It seems LightNCandy has some error options. Not sure which ones to use and how we'll forward it to the appropiate logs.

Event Timeline

Having actual error detection for this run-time failure would have prevented T219359: lang attribute of page title is empty.

Krinkle renamed this task from Template engine should emit warning if unconditional property doesn't exist to Mustache/TemplateParser should emit warning if property doesn't exist.Apr 2 2019, 3:45 AM
Krinkle triaged this task as Medium priority.
Krinkle moved this task from Unsorted to Add / Create on the Technical-Debt board.
Krinkle added a project: Wikimedia-Incident.

So I suppose we'd be checking variables are defined. It would mean we'd have to ensure certain template values were defined as null (and not undefined) as null is a perfectly valid template value.

For this to be feasible we'd need a way to access the variable names used inside a template.
I have another use case for that - see addMessagesToTemplateData - but the solution I came up with there didn't seem very optimal:
https://gerrit.wikimedia.org/r/c/mediawiki/core/+/584068/18/includes/skins/SkinMustache.php#71

I think having access to that information is the difficult part here. If that's in place however such complaints should be easy to deal with.

I came across this today - https://github.com/zordius/lightncandy#template-debugging - seems this should be built into Lightncandy.

Change 611418 had a related patch set uploaded (by Jdlrobson; owner: Jdlrobson):
[mediawiki/core@master] POC: Refuse to process templates with assumed null values

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

FYI from the mustache spec "By default a variable "miss" returns an empty string. This can usually be configured in your Mustache library. The Ruby version of Mustache supports raising an exception in this situation, for instance."

I don't know if lightncandy supports a miss variable. If it does, that would be useful (but I can't find one!)

I don't know if lightncandy supports a miss variable. If it does, that would be useful (but I can't find one!)

If we're okay with an error, it looks like FLAG_ERROR_EXCEPTION will do the trick.

This one might be overkill, but does make missing variables visible: FLAG_RENDER_DEBUG.

I think we already use FLAG_ERROR_EXCEPTION ?
https://github.com/wikimedia/mediawiki/blob/master/includes/TemplateParser.php#L67

I don't think missing variables count as errors in Lightncandy? So we might need an upstream feature request?

Change 611418 abandoned by Jdlrobson:
[mediawiki/core@master] POC: Refuse to process templates with assumed null values

Reason:
Was an experiment. Not good for production - but we've had a few high priority regressions without this.

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