Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error handling for invalid JSON #34119

Open
caseymilne opened this issue Aug 17, 2021 · 1 comment
Open

Improve the error handling for invalid JSON #34119

caseymilne opened this issue Aug 17, 2021 · 1 comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.

Comments

@caseymilne
Copy link

What problem does this address?

As JSON files are increasingly important (to FSE) and block development, and as there will be more manual editing of JSON going forward (post FSE going live) it is important to handle the issue of silent failure caused by JSON parsing errors. It only take one keystroke to break an FSE site. Just edit the theme.json that is parsed and controls everything, add one trailing comma, and your site is dead. Any block or Site Editor can be broken with one keystroke because JSON validation is very precise, it either validates and can be parsed or it cannot be parsed in which case the response from the PHP parsing is null. The result, everything breaks.

What is your proposed solution?

I would recommend using a TRY/CATCH approach with prominent error messaging. First we use PHP exception handling around all calls to json_decode() that are used to parse block JSON definitions and FSE theme.json files. If these cannot be parsed we aim to make this obvious to the site owner or developer through alerts and/or logging functions.

Bottom line is we should not allow a single keystroke to break a site due to a json_decode failure which can be caused so easily given users are being encouraged to manually edit JSON files. All it takes is this:

The code below pasted into any theme.json will NOT parse due to the trailing comma:

"supports": [ "valid_item": "valid_item_value", <<<< Trailing slash here means silent death. ]

Anybody that copy/pastes code into and around their JSON files will eventually make the mistake of leaving a trailing slash. For those doing this work regularly we know silent death equals JSON trailing slash, but for many millions of users it will result in hours or days of fruitless debugging.

@skorasaurus
Copy link
Member

Has this still been an issue for you ? There has been some work to improve this at #32404

@annezazu annezazu added [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") and removed [Feature] Full Site Editing labels Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants