pedroborges / kirby-blade-template

⬢ Laravel Blade template component for Kirby CMS.
MIT License
27 stars 3 forks source link

Error reporting #1

Closed fvsch closed 6 years ago

fvsch commented 7 years ago

So I used the master.blade.php and default.blade.php examples from the README, but got an error catched by Whoops:

Whoops \ Exception \ ErrorException (E_ERROR) Method Illuminate\View\View::__toString() must not throw an exception

And nothing in the stack trace, so Whoops showed my index.php, which was not very useful.

With Whoops disabled, I get this error printed in the page:

Fatal error: Method Illuminate\View\View::__toString() must not throw an exception in /Users/Florens/[…]/index.php on line 0

Turned out I was using @extends('layouts.master') but had put my master.blade.php at the root of the templates folder, rather than in a layouts subfolder. But with no relevant errors, that can be hard to figure out.

In this specific case, both the basic error and the Whoops error handler page show the same unhelpful error. Here is a case where Whoops shows that unhelpful error but the basic error output is more helpful:

@section('title', $page->doesntexist)

Basic output:

Notice: Undefined property: Page::$doesntexist in /Users/Florens/[…]/site/cache/d2039ed96c3f8c364028a47d23fef68b5cfe6b8d.php on line 1

Whoops output:

Whoops \ Exception \ ErrorException (E_ERROR) Method Illuminate\View\View::__toString() must not throw an exception

For the record, I wrote https://github.com/fvsch/kirby-twig and since Twig was reporting meaningful errors but not adding them to a stack trace, I had to skip using Whoops and catch the errors myself to display an error page. Feel free to reuse my code if you think you want to do something similar.

pedroborges commented 7 years ago

You could use @extends('master') and leave the file on the templates root, but it's better to group layouts in it's own subfolder, thus @extends('layouts.master') is preferred. I'll add a note on thereadme.md` to better explain that the dot syntax means subfolder.

I got the Undefined property and Fatal error: Method Illuminate\View\View::__toString() must not throw an exception errors a few time too. The error message is indeed not very helpful. I haven't thought of catching the errors myself, I'll definitely look into that. Thank you very much for the suggestion!

I'll check out the kirby-twig code too 😉

SirNovi commented 7 years ago

+1 for useful error messages


And Thanks @pedroborges for the nice plugin. Now I can get used to working with blade with my kirby projects and feel right at home when trying to get ahead with laravel.

pedroborges commented 6 years ago

@fvsch and @SirNovi, I finally got time to work on a fix for this issue and it turned out to be a simple one, yet hard to spot.

Please check out the develop branch of this repo for a fix. I'll tag a new version in the next few days.