arathunku / gulp-translator

*not maintained*
MIT License
11 stars 12 forks source link

How to catch parser error #7

Open blaues0cke opened 7 years ago

blaues0cke commented 7 years ago

I use gulp-translator with gulp-watch. Everything works fine until I save a corrupt yml file like:

foo: "bar"
bar: "foo",

In this case yamljs will crash and everything after it will crash then, too:

Projects/foo-frontend/node_modules/yamljs/lib/Parser.js:410
        throw e;
        ^
Error: Unexpected characters near ",".

I use gulp-translate like this (with gulp-load-plugins):

.pipe(
    plugins.translator(
        {
            lang:            'de',
            localeDirectory: 'dist/tmp/index/'
        }
    )
)

So how can I catch (and skip) this error to make sure, gulp-watch is starting over?

arathunku commented 7 years ago

Hello @blaues0cke,

this project is not actively maintained (last commit 2015, there's a note about that in the top desc.) but I'd gladly accept a PR to fix this if you had a spare moment to work on that.

It looks like it should catch the error in https://github.com/arathunku/gulp-translator/blob/master/lib/translator.js#L74 and print warning in case of a problem. I'm also thinking there should be an option like bail so we could fail loudly on parsing error (useful for CI server).

Cheers

blaues0cke commented 7 years ago

Thank you, I will digg into this to write a fix the next days! 👍

blaues0cke commented 7 years ago

@arathunku Took me some time to continue this, tried to create pr that is small as possible: https://github.com/arathunku/gulp-translator/pull/8

With this change, the crash is not "that fatal" so a gulp-watch will continue: image