Can not catch Error in Stream Mode
See original GitHub issueWhen trying to make a query with a problem in the query eg. wrong columnname while in Stream mode event.js throws an error which can not be catched. Subscription to the “error” event will be processed but the underlying error will still be thrown. The error can not be catched in the query callback nor promise and leads to App Crash.
Expected behaviour:
Error should only be thrown through error Eventhandler or Promise/Callback.
Actual behaviour:
Error is thrown in error Event and within events.js:
events.js:174
throw er; // Unhandled 'error' event
^
RequestError: Incorrect syntax near the keyword 'Table'.
Configuration:
sql
.connect(connection)
.then(pool => {
let request = pool.request();
request.stream = true;
let sql = "SELECT nonsense FROM Table";
let ws = fs.createWriteStream("output.txt");
request.on("error", err => {
console.log("Error in Stream", err.code);
});
request.pipe(through).pipe(ws);
request.query(sql).catch(err => {
console.log("error in Promise", err.code);
});
});
Software versions
- NodeJS: 10.17.0
- node-mssql: 6.1.0
- SQL Server: 2017
- Driver: Tedious
Issue Analytics
- State:
- Created 4 years ago
- Comments:13
Top Results From Across the Web
mssql - uncaughtException in Stream Mode - Stack Overflow
I was able to log the error while listening to readStream.on('error') but it still throws an uncaughtException . Software versions "mssql": "^ ...
Read more >How to handle stream errors? - Mario Kandut
Unhandled stream errors crash the application. One option to handle stream errors is to attach an event handler and listen to error events. ......
Read more >How Error Events Affect Piped Streams In Node.js - Ben Nadel
The "error" still doesn't affect the individual streams; but, Node.js will unpipe the streams depending on the source of the error.
Read more >Handling uncaught exceptions using Confluent
In this tutorial, learn how to handle uncaught exceptions using Confluent, with step-by-step instructions and examples.
Read more >Catching errors on Gulp.js - Boris - Medium
Watch mode is important thing of modern build systems, especially for ... If there is no listeners on `error` event on some stream, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
fyi, seeing this exact scenario as well
Sure 😃 Yes the Error in stream will be executed. The Error in Callback/Promise will not. I put a try/catch around the query and even the whole statement both will not be catched.
The Output is: