Page MenuHomePhabricator

TemplateData: Get better error messages for JSON syntax errors
Open, LowestPublicFeature

Assigned To
None
Authored By
Ironholds
Jul 1 2013, 6:41 PM
Referenced Files
F34099979: image.png
Feb 10 2021, 9:15 PM
F34099994: image.png
Feb 10 2021, 9:15 PM
F34099996: image.png
Feb 10 2021, 9:15 PM
F34099977: image.png
Feb 10 2021, 9:15 PM

Description

Enhancement request for more informative error messages - as simple as "Syntax error in JSON on line foo." would be better than the current message, which is just "Syntax error in JSON."

image.png (2×3 px, 461 KB)
image.png (2×3 px, 448 KB)

Details

Reference
bz50511

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:57 AM
bzimport added a project: TemplateData.
bzimport set Reference to bz50511.

It is in my opinion not feasible to get line numbers because we use a native PHP extension to parse the JSON.

If the JSON syntax itself is invalid, there is nothing we can do. Best case scenario the parser gives the type of error ("Unexpected comma", "Expected closing curly brace" etc.) but a line number is unlikely.

Once the JSON is parsed, the TemplateData validation itself (e.g. sets referring to existing parameters) we have full control over and gives pretty informative errors with the full path to the property.

Unexpected property "params.user.blabla".
Property "params.timestamp.description" is expected to be of type "string|object".

etc.

Presumably this could be done if bug 50169 was implemented, though. :-)

weskaggs wrote:

Displaying the contents of the line at which an error is detected, with a few lines around it for context, would be almost as useful as a line number. Of course the actual error can be a long way off from the point at which a syntax error is detected, but the information would still be helpful. Adding information about the type of error would make it even better. Really any information at all about the nature of the error would be an improvement.

For the moment, you can use TemplateDataEditor to be able to create the <templatedata/> without editing any real JSON.

http://en.wikipedia.org/wiki/User:NicoV/TemplateDataEditor

(In reply to comment #2)

Presumably this could be done if bug 50169 was implemented, though. :-)

Well, in case of bug 50169 (VisualEditor plugin for TemplateData) there would never be a syntax error in the JSON because the user wouldn't be editing it directly. They'd be using a form-like interface to interact with it (VE would generate the JSON which is always valid).

However if the VE plugin would have a raw mode to edit the JSON (e.g. using an Ace surface like Extension:CodeEditor does), we could use its JSHint integration to get inline errors by line/char highlighting (e.g. like in Sublime).

Krinkle moved this task from Backlog to Next-up on the TemplateData board.
Jdforrester-WMF lowered the priority of this task from Low to Lowest.Sep 17 2015, 6:38 PM
Jdforrester-WMF moved this task from Next-up to Backlog on the TemplateData board.
matmarex subscribed.

This is not the same issue as T256574.

T256574 is about the error message when clicking the "Manage TemplateData" button to open the "Template documentation editor" dialog:

image.png (2×3 px, 502 KB)
image.png (2×3 px, 424 KB)

This is about the error message when clicking "Publish changes": (currently this error doesn't appear at all, that's yet another separate issue filed as T258790)

image.png (2×3 px, 461 KB)
image.png (2×3 px, 448 KB)
thiemowmde changed the subtype of this task from "Task" to "Feature Request".Nov 29 2021, 8:13 AM
thiemowmde subscribed.

While I agree this is a valid feature request, I'm afraid there isn't much we can do at this point. I tried to annotate the generic error message with what json_last_error_msg() reports. All it says is "Syntax error". 😞 We would need to use another JSON parser to fulfill this feature request. That's unlikely to happen.