crissdev / gulp-yaml

A Gulp plugin to convert YAML to JSON
MIT License
24 stars 7 forks source link

plumber is invalid when error occurred #12

Closed zz5840 closed 6 years ago

zz5840 commented 6 years ago

if i add a comma to the end of a line, this plugin will throw a YAMLException which will break gulp watch. i tried to add gulp-plumber to prevent it, but it doesn't effect how could i solve it

image image

ehmicky commented 6 years ago

I would be curious about the opinion of @crissdev on this, but I think it's a problem with Gulp, not with gulp-yaml. Specifically if for any reason this plugin has incorrect input (including a wrong comma at end of a line), it should emit an error event to the underlying stream.

Your problem seems to be that gulp.watch() stops when any Gulp plugin emits an error event. This problem was fixed in the latest version of Gulp (version 4), you should try to upgrade to it.

crissdev commented 6 years ago

@zz5840 @ehmicky Sorry for the delay on this one.

https://github.com/crissdev/gulp-yaml/blob/7a7a372051bb44a289bd2f93462214c98a7a455f/index.js#L24

It seems getFileContents returns null/undefined if the parsed file has a syntax error. I cannot test this right now but maybe this might be the case.

Furthermore, I see the callback is called twice in case of an error (L63 && L27)

@zz5840 Could you edit node_modules\gulp-yaml\indexjs in line 24, with the follwing snippet and see if it solves this problem?

const result = getFileContents(file, options, stream, callback)

if (result) file.contents = result
zz5840 commented 6 years ago

@crissdev it's affected, but when will you update and publish it to npm, or need i create a pr

zz5840 commented 6 years ago

@ehmicky oh thx, it's really helpful