question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not catch Error in Stream Mode

See original GitHub issue

When 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:closed
  • Created 4 years ago
  • Comments:13

github_iconTop GitHub Comments

2reactions
smfergusoncommented, Apr 16, 2020

fyi, seeing this exact scenario as well

2reactions
Rafael-Dabrowskicommented, Mar 14, 2020

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:

Error in Stream EREQUEST
events.js:174
      throw er; // Unhandled 'error' event
      ^

RequestError: Incorrect syntax near the keyword 'Table'.
    at handleError (C:\node\Demos\mssql\node_modules\mssql\lib\tedious\request.js:366:15)
    at Connection.emit (events.js:198:13)
    at Parser.tokenStreamParser.on.token (C:\node\Demos\mssql\node_modules\tedious\lib\connection.js:832:12)
    at Parser.emit (events.js:198:13)
    at Parser.parser.on.token (C:\node\Demos\mssql\node_modules\tedious\lib\token\token-stream-parser.js:37:14)
    at Parser.emit (events.js:198:13)
    at addChunk (C:\node\Demos\mssql\node_modules\readable-stream\lib\_stream_readable.js:298:12)
    at readableAddChunk (C:\node\Demos\mssql\node_modules\readable-stream\lib\_stream_readable.js:280:11)
    at Parser.Readable.push (C:\node\Demos\mssql\node_modules\readable-stream\lib\_stream_readable.js:241:10)
    at Parser.Transform.push (C:\node\Demos\mssql\node_modules\readable-stream\lib\_stream_transform.js:139:32)
Emitted 'error' event at:
    at Request.emit (events.js:203:15)
    at handleError (C:\node\Demos\mssql\node_modules\mssql\lib\tedious\request.js:369:16)
    at Connection.emit (events.js:198:13)
    [... lines matching original stack trace ...]
    at Parser.Readable.push (C:\node\Demos\mssql\node_modules\readable-stream\lib\_stream_readable.js:241:10)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found