anlutro / laravel-4-smart-errors

Smarter error handling for Laravel 4
65 stars 13 forks source link

Seeing smart errors on 4.2 #25

Closed levitating closed 8 years ago

levitating commented 8 years ago

I am having a strange error on Laravel 4.2 where I see the errors on this page :

https://github.com/anlutro/laravel-4-smart-errors/blob/master/src/views/generic.blade.php

Could you write a bit of documentation on which conditions exactly result in the display of that page? That would be very helpful.

anlutro commented 8 years ago

When you say that you see "the errors", what exactly do you mean? Do you see the exception that triggered the error handler, or is the error unrelated?

I should definitely work on the documentation on when the error page is being shown. Unless I'm forgetting something, the conditions are:

levitating commented 8 years ago

I am doing this :

Route::get('/tester', function()
{
    $users = User::all();
    return View::make('protected.user.show', ['users' => $users]);
});

And getting this EXACT page :

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>smarterror::error.genericErrorTitle</title>
    <style>
        * {
            font-family: sans-serif;
            line-height: 1.4em;
        }

        body {
            background: #fcfcfc;
            -webkit-font-smoothing: antialiased;
            -moz-font-smoothing: antialiased;
            -ms-font-smoothing: antialiased;
            -o-font-smoothing: antialiased;
            font-smoothing: antialiased;
        }

        h1 {
            text-align: center;
            font-size: 3.5em;
        }

        .error-message {
            padding: 30px;
            background: #fff;
            color: black;
        }

        a {
            color: black;
        }

        @media  screen and (min-width: 800px) {
            h1 {
                margin-top: 75px;
            }
            .error-message {
                max-width: 700px;
                margin: 50px auto;
                border-radius: 10px;
                border: 1px solid #ddd;
            }
        }
    </style>
</head>
<body>

<h1>smarterror::error.genericErrorTitle</h1>

<section class="error-message">

    <p>smarterror::error.genericErrorParagraph1</p>
    <p>smarterror::error.genericErrorParagraph2</p>
    <p style="text-align:center;">
            <a href="/">smarterror::error.frontpageLinkTitle</a>
    </p>

</section>

</body>
</html>

There doesn't seem to be any indication on from where this page is being generated, thus I am asking in which conditions we could see this generic error page that has no debug details to retrace its origin.

anlutro commented 8 years ago

The most likely cause is that app.debug is set to false in the config. This can happen if your environment detection in bootstrap/start.php is wrong.

You should be able to check your logs (app/storage/logs/apache2handler.log by default) and find the original exception there.

levitating commented 8 years ago

Ah that was it! Thank you.

A suggestion might be to display a clearer message when this happens, such as "Smart Errors, please turn on debug mode to see details."

anlutro commented 8 years ago

The problem with that is it would also show up to your end users when you deploy to production. I think it has to be left the way it is, really.

I will have a look at improving the readme, though.

levitating commented 8 years ago

Well if you look a the logic used by Laravel itself, if debug is off you see a general error. No details but the error is clean.

The html file i posted above is not clean, it shows place holders for errors, and developers do not necessarily realize that it is the equivalent of Laravel's "clean error page" meant for the end users. I see what you are saying, but I believe that page can be improved, when there are no specific errors to be shown, a general error should be displayed instead of the place holders.

Maybe you could even use the same error page as Laravel's in this case. That would at the least avoid all confusion and remind the developer to activate debug mode to find the source of the error right away.

anlutro commented 8 years ago

The reason you're getting placeholders is that you're missing translations for your locale. If you switch to 'en' the placeholders should be replaced, you can also add your own as documented here.

levitating commented 8 years ago

Ah I didn't realize this about locale.

In this case I agree with you. Would it be possible to fallback to EN when translation is missing?

anlutro commented 8 years ago

I haven't used it myself, but http://laravel.com/docs/4.2/localization describes a "fallback language" config. Maybe that does the job?

levitating commented 8 years ago

Yes that's it

anlutro commented 8 years ago

I've expanded the readme a bit, specifically here.