Fatal errors show blank page in HHVM Laravel/Lumen, fix for HandleExceptions.php
After installing Homestead with HHVM and Laravel/Lumen, I noticed fatal errors would just give a blank page. I also made sure to add these settings:
in /etc/hhvm/php.ini
hhvm.server.implicit_flush = true
hhvm.error_handling.call_user_handler_on_fatals = true
I entered some random junk sdfkljs (no semi-colon) in my routes.php file to throw a fatal error and the error doesn't output to the browser. This issue was reported on the HHVM github here. I tinkered around with Foundation\Bootstrap\HandleExceptions.php and fixed the problem.
The Fix in vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
// **** Add this to hold fatal error
protected static $fatalError = null;
...
public function handleError($level, $message, $file = '', $line = 0, $context = array())
{
// **** Add this, loads fatal error
if ($level & (1 << 24)) {
self::$fatalError = array(
'message' => $message,
'type' => $level,
'file' => $file,
'line' => $line
);
}
if (error_reporting() & $level)
{
throw new ErrorException($message, 0, $level, $file, $line);
}
}
...
// *** Update this function so it can handle the fatal
public function handleShutdown()
{
$error = error_get_last();
if(self::$fatalError){
$error = self::$fatalError;
}
if ( ! is_null($error) && $this->isFatal($error['type']))
{
$this->handleException($this->fatalExceptionFromError($error, 0));
}
}
...
protected function isFatal($type)
{
// *** Add type 16777217 that HVVM returns for fatal
return in_array($type, [16777217, E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]);
}
...
Also, note, in Lumen the code there seems to be missing the shutdown functionality.
Instead of going through the whole Pull Request process, I thought I'd just report the issue here so you can update the source with the fix. Let me know, thanks! (And thanks for this wonderful framework! Looking forward to Laracon Kentucky!)
+1 for this issue!
+1 Just added these changes and now get whoops page.
Something's not working with the stacktrace but it's a definite improvement to see the exception message.
For implementing a non-existing interface here is what I get in the browser
Exception
FatalErrorException in line -1:
Undefined interface: App\Services\FooInterface
Stacktrace:
1. in line -1
Should be FooService line 7
We're open to PRs.
@prograhammer Could you look at the problem in my reply above and see if you see a problem there? I can look into it more on my next day off from work but that will be a few days.
This issue has been fixed in symfony/symfony#14967, but at what release will that get into laravel/lumen?
This issue appears to be resolved at of the latest tag (5.1.3) of laravel and lumen.
It seems that this issue was not fixed. I'm using Homestead and I'm still getting a blank page on fatal errors.
Not fixed
It's up to HHVM to fix this issue I'm afraid. Please ask them.
I formally give up on trying to solve this problem. I'm just going to develop in a mixture of PHP7 and HHVM (and continually read the log files to dissect errors).
This seems to be caused by a formal security-based policy decision by HHVM team so they won't budge. In which case, it's up to the Laravel team to detect if site is running HHVM (i.e. if (defined('HHVM_VERSION'))) and put in work-around code.
Having said that, work-around code doesn't work for me.
I just discovered a weird anomaly:
-
no changes to php.ini: It shows debug stack trace properly: e.g
NotFoundHttpException in RouteCollection.php line 161:It shows blank page for other types of errors like syntax errors - but you get full error in log file. -
If I add
hhvm.php7.all = truetophp.ini
It shows blank page for everything.
- If I don't add
hhvm.php7.all = truetophp.ini, but follow the instructions above: i.e. addhhvm.server.implicit_flush = truehhvm.error_handling.call_user_handler_on_fatals = truetophp.iniand make the changes tovendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
It shows an overly simplified stack trace. It shows something like this:
FatalErrorException in routes.php line 28: syntax error, unexpected T_STRING
in routes.php line 28`
and NO other information!
At least previously, it showed the full stack trace in the log file. In this case, the overly simplified error message is also the overly simplified error in the log file.
As I said, it's up to HHVM to fix this.