Closed omencat closed 9 years ago
I believe that's expected behaviour? If you don't want to gulp-tslint to throw an error, you can set the emitError
option to false
.
The message in question is
stream.js:94
throw er; // Unhandled stream error in pipe.
^
This doesn't display when I run tslint.
Yes, that is by design.
Closing as won't fix.
The gulp-tslint docs say it will throw a plugin error (from https://github.com/gulpjs/gulp-util). An example from the docs:
[gulp] Error in plugin 'gulp-tslint': Failed to lint: invalid.ts
But the error is occuring in stream.js and the message doesn't even look like a plugin error (aka it does not include the module name etc).
You can listen for the error event in the stream, but if you throw it you get the same message. So it seems intentional. It would just be nice if it could be more clear that its intentional.
Thanks for the clarification.
And if you would like even more clarification, pipe errors should actually be passed up to gulp. If you return a stream in your task function, gulp should be able to handle the on error event. If you are using the callback parameter, you should pass any errors to it. If you are using a promise, make sure to reject it with your error. Then when you look in the console, you'll get a message more like this:
[13:52:44] Starting 'tslint'...
[13:52:44] [gulp-tslint] error (no-unused-variable) app.ts[21, 7]: unused variable: 'test'
[13:52:44] [gulp-tslint] error (typedef) app.ts[21, 11]: expected variable-declaration: 'test' to have a typedef
[13:52:44] 'tslint' errored after 168 ms
[13:52:44] Error in plugin 'gulp-tslint'
Message:
Failed to lint: app.ts[21, 7]: unused variable: 'test', app.ts[21, 11]: expected variable-declaration: 'test' to have a typedef.
Notice in your example that gulp never terminated the task with an output something like: [13:52:44] 'tslint' errored after 168 ms
This means that you aren't passing any stream errors up to gulp, meaning that the task ends on the error being thrown rather than gulp handling it. You should be able to fix this by simply returning the stream in your function.
There is nothing to fix in gulp-tslint. This can be closed. The issue was related to improper error handling in the user created task. They needed to return the stream in the task function.
Yeah, it seems to be a best practice to return the stream, as gulp-tslint is asynchronous ( from https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-tasks-in-series.md ), as it's used as a hint for task completion.
If the gulp does returns the stream, the error message is "nice" and handled by gulp. I updated the readme and the test files.
Closed after updating the examples, thanks for your help :).
Well best practice is to do one of three things: return a stream, return a promise, or use the callback. Returning a stream is the only one where gulp will handle errors (using the error event from the stream). The other two require that you listen for errors on your streams and pass the error to your promise rejection method or the task callback.
I am getting an error just using your example code in the readme:
gulp.task('tslint', function () {
return gulp.src('scripts/app/main.ts')
.pipe(tslint())
.pipe(tslint.report('verbose', {
emitError: false
}));
});
I have tried with or without the emitError option, just nothing i do works. I dont get any lint errors just parsing error. This is with a file which has one comment in it, or indeed empty, it just always crashes out no matter what i do with the following:
stream.js:94
throw er; // Unhandled stream error in pipe.
^
SyntaxError: Unexpected token
at Object.parse (native)
I think we need more information. Can you show us the content of main.ts? Also, are you getting any type of stack trace?
Does tslint.json exist? Does it's contents pass validation ( http://jsonlint.com/ )?
Apologies for this, I tried going right back to trying tslint which was also failing. It transpires that tslint cannot cope with a tslint.json file which is encoded as UTF8 with a BOM. That's what the unexpected token was, it was the BOM characters.
Much apologies for posting this as an issue for you when it wasn't an issue for your project in the end.
I created a new feature task for reporting a better error for this case.
I also ran into this problem. Using Visual Studio, I created tslint.json, which gave it UTF8 encoding. Changing to ANSI resolved the error.
I can run tslint on the same file OK, but using the sample gulp-tslint task results with: stream.js:94 throw er; // Unhandled stream error in pipe.
console: