I am jumping onto a node.js project where some errors fail silently and the app doesn't throw any errors unless I put it in a try..catch
block. For example:
console.log(ok) // doesn't throw any errors during runtime; the api just fails silently.
try {
console.log(ok)
} catch(e) {
console.log(e)// throws ReferenceError: ok is not defined
}
Does anyone know why this might be?
Thank you in advance!
Does anyone know why this might be?
Clearly, code in a containing scope is catching and suppressing errors. Which is an unfortunate, but common, practice.
Sadly you'll just have to root out that code, there's no real shortcut. You could run with --inspect
(on recent versions of Node) and tell the debugger to stop on all exceptions, even caught ones, which may help you track them down some. But it's going to be tedious, I'm afraid.
One possible further thought: On only-slightly-older versions of Node, unhandled Promise rejections are not reported. So if that code is inside (say) a Promise executor (the function you pass new Promise
) or a then
or catch
handler (or an async
function), the throw is being converted to a promise rejection. The latest versions of Node report unhandled Promise rejections. (In the not-distant-future, they'll also terminate the Node process.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With