simon-dt / gulp-twig

Twig plugin for gulp.js, The streaming build system. Looking for maintainer or collaborators. See wiki
https://github.com/zimmen/gulp-twig/wiki/Looking-for-maintainer-or-collaborator(s)
MIT License
62 stars 33 forks source link

Handling errors #18

Open tremby opened 8 years ago

tremby commented 8 years ago

In my gulp task to compile twig templates, if there's an error (such as in {% include 'file-which-doesnt-exist.twig' %}) I get a huge stack trace.

What's the recommended way to set up my gulpfile so I have just a short message on errors?

Setting onError to something to echo a short message doesn't seem to do anything (it doesn't seem to run) and setting errorEchoToConsole to true doesn't seem to do anything either.

I also tried adding .on('error', gutil.log) to the stream, but this doesn't have any effect.

tremby commented 8 years ago

There was no error actually being thrown. Maybe something changed upstream: it looks like you now need to pass rethrow: true as part of twigOpts. Adding this in gulp-twig/index.js around line 36 leads to the error being properly thrown and caught.

Still wondering what the best way is to display a shorter error message. It looks like the twig package is outputting it all no matter what settings are passed.

simon-dt commented 8 years ago

Hmm, i'd have to dive into that a bit. Perhaps your own errorhandler that gets the full error so you can pick whatever you want to log or put into the stream.

tremby commented 8 years ago

The thing is, upstream twig doesn't throw you the error at all unless you pass that rethrow option. It has its own catch block, catches its own error and produces that big stack trace.

tremby commented 8 years ago

And even if you do pass rethrow: true, it still outputs the error to stdout before throwing it again. Messy.

tremby commented 8 years ago

See https://github.com/justjohn/twig.js/blob/6b71c7e19e24c8c646aa530f3d0e49e932aaa46c/twig.js#L550 and https://github.com/justjohn/twig.js/blob/6b71c7e19e24c8c646aa530f3d0e49e932aaa46c/twig.js#L612

jameelmoses commented 7 years ago

Experiencing the same thing as @tremby.

Can you provide an example of rolling my own error handler?

olets commented 6 years ago

@tremby what's your feeling about this these days? I've had good luck with gulp-plumber but it's been a while since I looked into this end of things

tremby commented 6 years ago

I haven't used gulp-twig in quite some time, but this was always something which annoyed me, and maybe I'll have to come back to one of those projects which uses this at some point. So I guess my feeling about this is that a solution should be found. Looks like others are interested in a fix too.