Display fatal/notice errors in browser
Asked Answered
C

2

8

Well I just started with hhvm/hack. But I wanted to display the errors to the browser but didnot got it working.

I set the ini settings as followed

error_reporting(E_ALL);
ini_set('display_errors', '1');

According to a var_dump of ini_get the values were set to

string(5) "32767"
string(1) "1"

But when I did

<?hh

error_reporting(E_ALL);
ini_set('display_errors', '1');

throw new InvalidArgumentException('test');

When I visited the page via de browser I would just get a white screen and a 500 http header. So no explaintion of the fatal/exception error.

Would I however go via the terminal hhvm index.php It would show;

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'test' in /var/www/public/index.php:3
Stack trace:
#0 {main}

So now the question. How does it come I don't get any messages in the browser, but do in the cli? And the second one is, how do I get it working in the browser to show messages.

I came across this question and this one. But the first, well is the same, but unanswerd. And the second is saying something about static checking. IE that an int is given etc, at least that is what I think he means.

Other question I came by, which looked like mine, but again unanswered.

And according to the docs it should work I guess.

Reading more on the docs I came accross

Although display_errors may be set at runtime (with function ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.

So I thought well an Exception is a fatal error so I just did $test = $bar + 1;

This let in the cli to

Notice: Undefined variable: bar in /var/www/public/index.php on line 8
int(1)

Again in the browser

int(1) 

So I don't get notices either.

When I restart hhvm service hhvm restart I also get the error message Log file not specified under daemon mode. don't know if it has anything to do with it

Clari answered 2/7, 2014 at 6:23 Comment(0)
C
6

Well it took me some searching but finally found the answer, see this github post. It can't however display fatal errors. But notices are displayed

So I wrote my own error handler; it is not complete but does the job for now.

Warning, no check for ini display_errors

set_error_handler(function ($errorNumber, $message, $errfile, $errline) {
    switch ($errorNumber) {
        case E_ERROR :
            $errorLevel = 'Error';
            break;

        case E_WARNING :
            $errorLevel = 'Warning';
            break;

        case E_NOTICE :
            $errorLevel = 'Notice';
            break;

        default :
            $errorLevel = 'Undefined';
    }

    echo '<br/><b>' . $errorLevel . '</b>: ' . $message . ' in <b>'.$errfile . '</b> on line <b>' . $errline . '</b><br/>';
});
Clari answered 2/7, 2014 at 9:46 Comment(1)
Thanks very helpful. Worked for me to get a PHP Notice to display in HHVM.Polycotyledon
B
1

It's possible to fall back to php when hhvm fails. Pretty simple to do that - https://bjornjohansen.no/hhvm-with-fallback-to-php. I understand you can attach php fallback per error code (like 404). So isn't it possible to fall back to php server that shows a page which loads the hhvm error log?

Buckram answered 17/2, 2016 at 8:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.