framework icon indicating copy to clipboard operation
framework copied to clipboard

Fatal errors show blank page in HHVM Laravel/Lumen, fix for HandleExceptions.php

Open prograhammer opened this issue 11 years ago • 12 comments

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!)

prograhammer avatar May 14 '15 18:05 prograhammer

+1 for this issue!

zippex avatar May 17 '15 22:05 zippex

+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

isimmons avatar May 21 '15 18:05 isimmons

We're open to PRs.

GrahamCampbell avatar May 31 '15 18:05 GrahamCampbell

@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.

isimmons avatar Jun 01 '15 17:06 isimmons

This issue has been fixed in symfony/symfony#14967, but at what release will that get into laravel/lumen?

zakhenry avatar Jul 07 '15 06:07 zakhenry

This issue appears to be resolved at of the latest tag (5.1.3) of laravel and lumen.

zakhenry avatar Jul 27 '15 03:07 zakhenry

It seems that this issue was not fixed. I'm using Homestead and I'm still getting a blank page on fatal errors.

marianperca avatar Dec 17 '15 20:12 marianperca

Not fixed

pjebs avatar Dec 26 '15 20:12 pjebs

It's up to HHVM to fix this issue I'm afraid. Please ask them.

GrahamCampbell avatar Dec 26 '15 20:12 GrahamCampbell

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.

pjebs avatar Dec 27 '15 03:12 pjebs

I just discovered a weird anomaly:

  1. 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.

  2. If I add hhvm.php7.all = true to php.ini

It shows blank page for everything.

  1. If I don't add hhvm.php7.all = true to php.ini, but follow the instructions above: i.e. add hhvm.server.implicit_flush = true hhvm.error_handling.call_user_handler_on_fatals = true to php.ini and make the changes to vendor/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.

pjebs avatar Dec 27 '15 03:12 pjebs

As I said, it's up to HHVM to fix this.

GrahamCampbell avatar Dec 27 '15 11:12 GrahamCampbell