-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 resilience to PHP Notices and Warnings #4936
Comments
Not sure this is very actionable, most of the time parsing network results is done by low level APIs ( If there's something to be done here, it's more likely server-side in the REST API framework to catch all these errors and invalid output when the response type is expected to be JSON and issue a proper issue response. |
Not dealing with this issue is a failure to satisfy Non Functional Requirements in the area of Resilience, Robustness and Reliability. If we don’t have documented NFR’s then we need them. Yes, the server could attempt to trap some responses, but not all of them.
What does window.fetch get before it attempts to parse the JSON? The console log shows it pretty clearly. |
Thanks again for the suggestion, @bobbingwide. I've filed this away in the Ideas project for future consideration. At this point in the Gutenberg development cycle, we're focusing on finishing the remaining features and then switching to bug fixing / polish. |
From https://make.wordpress.org/core/handbook/about/philosophies/#striving-for-simplicity
|
@bobbingwide Yes, I agree with that. |
So is the issue that the REST API response is prefixed by PHP notice, rather than being proper JSON? I don't see what this has to do with Gutenberg at all, it's an issue of the server not rendering a JSON entity correctly. Should Gutenberg be tolerant to these? Maybe. It's certainly a bandaid fix that helps brush over the underlying issue. What would be the fallback which should occur when it's not unserializable? Here's the current logic: gutenberg/packages/api-fetch/src/index.js Lines 54 to 60 in 186716f
By this, it would appear we're trying to see if it's a JSON response before trying to parse. So either the server is misreporting the non-JSON as |
I think a proper way to deal with this is trying to catch these errors/warnings in PHP before sending the response if the response is JSON and return a well-formatted JSON error instead. It could be a generic behavior to all REST API endpoints calls. |
Also, I don't like the idea of being tolerant personally because we'll be just hiding real issues. |
I agree about not being tolerant. It might be nice though to make the underlying errors a little more visible. Right now if you're getting an error you have to do a bit of spelunking inside devtools to track down the error message. There might be some inspiration to be found in how error messages are loaded in when trying to activate a plugin with PHP fatals: Some of the work the #core-php team is doing around WSODs during PHP upgrades might also be useful. |
Correct.
How would this work in practice, and reliably?
Notably, it's the client with the error handling in this case. If we wanted to follow this as inspiration, then the error handling would need to go in Gutenberg. |
@danielbachhuber Yeah, sorry I meant more in the UI inspiration not the technical implementation :) |
Some more user-friendly error handling than "Updating failed." or the other cryptic messages Gutenberg currently provides. |
@danielbachhuber I was thinking we could use this http://php.net/manual/en/function.set-error-handler.php and return something like That way the frontend could catch these errors properly and show a more meaningful message. |
Could be worth exploring. It wouldn't have caught #3102 though, as any sort of error handling would be registered midway through application load. I'm also not sure how reliable |
We also need to take into consideration that requests can fail before hitting the backend. If the JSON API is unavailable is one of them, but what if your request was blocked by mod_security or similar security implementations? These will usually provide a non-successful status code, and not much more without looking into logs. As an example, this is a rule blocking a user from saving, publishing, or having content autosaved:
They are seeing a message that saving failed, unfortunately there's not much information on why it failed, and what actions they need to take to not lose their content. |
It seems https://core.trac.wordpress.org/ticket/44534 could address at least some of these problems. It appears WordPress isn't disabling error reporting like it's expected to, which could be the cause of some of these problems. |
Closing in favor of #10492 |
Issue Overview
As mentioned in today's core-editor meeting
I believe that Gutenberg could be significantly improved if it could detect unexpected server responses, especially things like PHP Notices and Warnings
and it should
I have experienced a number of situations, where PHP Notices and Warnings get returned along with the validly formed JSON response.
Steps to Reproduce (for bugs)
For a particularly good example of a misbehaving plugin see https://github.com/bobbingwide/dinlo
Expected Behavior
It would be nice if Gutenberg could filter out what's not part of the JSON response and report the results based on that information.
It would also be nice if it was able to report nicely what the problem was.
Current Behavior
In the classic editor the messages appear. Many are just an annoyance but the editor works.
Possible Solution
Screenshots / Video
Here's the simplest example I could think of.
Add an HTML comment to the top of the gutenberg.php plugin.
<!-- 4936 -->
Related Issues and/or PRs
Todos
The text was updated successfully, but these errors were encountered: