Stucks
June 13, 2022, 4:03pm
1
I’m currently using Bedrock and Sage (sans Trellis) and seem to be forever coming across PHP warnings that are being generated by plugins, which then breaks certain functionality, even with the environment set to production.
Just really simple things like undefined indexes stops things from working.
If I understand correctly, this is Laravel elements added by Acorn that’s converting these Warnings and throwing Exceptions?
Obviously I can’t fix these problems in the plugins, so is there a way of suppressing them? It seems to be an annoyingly common occurrence.
TIA
Look at this gist.
Look at all the comments by Mike. He resolves some problems regarding Ajax calls…
Hope it will be useful
1 Like
Sage 10 (acorn
library) had some issues with earlier releases with error handling:
opened 03:09PM - 05 Apr 21 UTC
closed 01:23AM - 31 Oct 21 UTC
* [x] I've read the [guidelines for Contributing to Roots Projects](https://gith… ub.com/roots/.github/blob/master/CONTRIBUTING.md)
* [x] This request isn't a duplicate of an existing issue
* [x] I've read the [docs](https://roots.io/documentation/) and followed them (if applicable)
* [x] This is not a personal support request that should be posted on the [Roots Discourse](https://discourse.roots.io/) community
## Description
Note: `acorn` put the code of a previously deprecated package (on packagist) into its own repo.
There is a bug with the bitwise operation used in the condition to check for `error_reporting` as it doesn't work for disabled error_reporting or `error_reporting` without lower reporting levels:
https://github.com/roots/acorn/blob/a2ef0a5fe7a4b4d692838529a1b67c48245f0cbd/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php#L68
with `error_reporting` set to `0` or `E_ERROR | E_WARNING | E_PARSE` in order to skip `E_NOTICE` PHP errors,
the error will still be thrown, shown and destroy the page markup at that point with injected "rich" error HTML.
## Steps to reproduce
1. Configure for lower or none `error_reporting`, e.g. for staging in `config/environments/staging.php`
2. Trigger a PHP `E_NOTICE` message, e.g. an `Undefined index` error by accessing an undefined index of a PHP array:
Note that these lower level PHP errors still cause a "rich" HTML error message, which shouldn't happen.
**Expected behavior:**
PHP errors with levels to be ignored.
**Actual behavior:**
PHP errors with levels to be ignored are still thrown.
**Reproduces how often:**
Always.
## Versions
Bedrock:
````
### 1.15.3: 2021-03-12
* chore(deps): Bump roots/wordpress from 5.6.2 to 5.7 ([#578](https://github.com/roots/bedrock/pull/578))
````
## Additional information
Related: https://github.com/roots/acorn/issues/87
PHP warnings and notices caused PHP exceptions.
Currently I am using this code snippet to fix the error handling:
opened 12:50AM - 09 Feb 21 UTC
closed 01:23AM - 31 Oct 21 UTC
It looks like master is already on 2.0 now, which doesn't have this issue, but w… anted to raise it in case there is to be a maintenance release of the 1.x series, and to let others know about it.
#58 was to add functionality to ignore certain classes of error, adding the following code:
https://github.com/roots/acorn/blob/fa60ba1551dc96400b10aaa7f396a2fffd62e5c6/src/Acorn/Bootstrap/HandleExceptions.php#L186-L197
But from what I can see, this code doesn't work. It's checking if `ErrorException` is an instance of `'E_USER_DEPRECATED'`, which I don't believe will ever work. Something like:
```
$e->getSeverity() === constant($type)
```
is what I can come up with to get this to work as designed.
My workaround in a Sage 10 theme with Acorn v1.1.0 is to check if the Acorn error handler is the one registered, and if so, replace it with one that unconditionally throws an ErrorException
```
add_action('after_setup_theme', function () {
$previous_handler = set_error_handler(null);
// Check if the Acorn error handler was actually the one we just removed or not
if (!empty($previous_handler[0]) && $previous_handler[0] instanceof \Roots\Acorn\Bootstrap\HandleExceptions) {
set_error_handler(function ($level, $message, $file = '', $line = 0, $context = []) {
throw new ErrorException($message, 0, $level, $file, $line);
});
} else {
set_error_handler($previous_handler);
}
}, 6);
```
Edit: Had just this issue again with the Widgets page (PHP warnings and notices causing a PHP exception/oops screen).
2 Likes
Stucks
June 14, 2022, 9:07am
4
That’s the badger, fixed a number of my current issues.
Cheers!
1 Like
Stucks
June 14, 2022, 9:08am
5
Thanks, didn’t fix the issue, but i’ve added it nonetheless.