node-sqlite3
node-sqlite3 copied to clipboard
Not possible to capture errors from anonymous statements as events
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))