You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using .stream() query and postProcessResponse, that throws an error, then it is impossible to catch the error with .on('error'. The expected behaviour is that .on('error' should also catch an error that happened in postProcessResponse.
Minimal code to cause the issue.
Specific data is not needed.
constDATABASE='';// Name of the databaseconstUSERNAME='';// UsernameconstPASSWORD='';// PasswordconstHOST='';// Hostnamefunctionmain(){constknex=require('knex')({client: 'mssql',connection: {database: DATABASE,user: USERNAME,password: PASSWORD,server: HOST,},// A showcase what happens if postProcessResponse is a sync function which throwspostProcessResponse: (result,queryContext)=>{thrownewError('This is a test error');}});// Query does not matter since the issue is with postProcessResponseconststream=knex.raw('SELECT 1 as result').stream();stream.on('data',(row)=>{console.log('row',row);});// Should handle the error thrown in postProcessResponse// But it does notstream.on('error',(err)=>{console.error('error',err);});stream.on('close',()=>{console.log('closed');knex.destroy();});}process.on('uncaughtException',(reason)=>{// This should not fire since the error is caught in the stream// But it doesconsole.error('uncaughtException',reason);process.exit(1);});main();
If process.on('uncaughtException' is removed from the minimal code example, then the node process crashes with output containing throw er; // Unhandled 'error' event
The text was updated successfully, but these errors were encountered:
Environment
Knex version: 3.1.0
Database + version: Microsoft SQL Server 2019 + tedious 18.1.0
OS: Linux Mint 21
@smorey2
Bug
Actual behaviour and the expected one
When using
.stream()
query and postProcessResponse, that throws an error, then it is impossible to catch the error with.on('error'
. The expected behaviour is that.on('error'
should also catch an error that happened inpostProcessResponse
.Minimal code to cause the issue.
Specific data is not needed.
If
process.on('uncaughtException'
is removed from the minimal code example, then the node process crashes with output containingthrow er; // Unhandled 'error' event
The text was updated successfully, but these errors were encountered: