node-sqlite3 icon indicating copy to clipboard operation
node-sqlite3 copied to clipboard

Not possible to capture errors from anonymous statements as events

Open anszom opened this issue 6 years ago • 0 comments

Errors from sql statements, when not handled in a callback, are emitted as events on the statement object. The problem is that the statement object is not accessible, when the statement has been implicitly created, for example with db.run. See the following code as an example:

sqlite=require('sqlite3');
db = new sqlite.Database(':memory:')
db.on('error', function(err) { console.log('handled:', err) })
db.run('invalid sql') // results in an unhandled exception

I think that it is more consistent to forward these errors to the database object, for example add the following just before the return fn.call... at the end of normalizeMethod: statement.on('error', (err) => this.emit('error', err))

anszom avatar Aug 30 '17 15:08 anszom