Closed
Description
Moved from firebase/firebase-admin-node#89
-
Operating System version:
macOS Sierra 10.12.6
node/6.11.1 -
Firebase SDK version:
"firebase": "4.4.0",
"firebase-admin": "5.2.1", -
Library version:
-
Firebase Product: database
When an exception is thrown from a user callback (inside .once or .then)
the exception is raised as a uncaught exception event instead of
calling the .catch function.
const db = getDatabase();
const id = `/path/key`;
process.on('uncaughtException', function (err) {
// this event is called instead of the .catch(err)
console.error( "UNCAUGHT EXCEPTION " );
console.error( "[Inside 'uncaughtException' event] " + err.stack || err.message );
process.exit();
});
db.ref(id)
.once('value', snap => {
throw new Error('test');
})
.catch(err=>{
// This catch function is not ever called.
console.log('caught the error', err);
});
This behavior is not consistent with the standard promise model.
const promise = new Promise(function (resolve, reject) { resolve('ok'); });
promise
.then(value=>{
console.log(value);
throw new Error('test');
})
.catch (err=>{
// This catch function is called.
console.log('catch 1');
});