I use the large Cujo When library to provide a Promises / A + implementation for my Node project, although this question is not node-specific.
Generally, when it's excellent: it allows me to write more convenient, readable code.
However, when my callbacks end unexpectedly (referring to the property of a null variable, etc.), the exceptions are effectively swallowed, such as, for example, according to the Promises / A + specification. Unfortunately, this means I get no feedback about the error (except that the callback stops at this point). No type of error or message, line number.
To illustrate:
// hypothetical asynchronous database query database.query(queryDetails).then(function(result) { var silly = 3.141592654; silly(); // TypeError: number is not a function! process(result); // this code is silently never executed });
I can come up with several (unacceptable) ways to solve this problem:
- providing response failures for each
then call (to output the cause / exception to the console) - wrapping all callback bodies in try-catch
- clog the codebase with the help of 'sign logs' ala
console.log('I got here 123')
Am I just doing it wrong? Of course, I'm not alone in finding debugged errors on promises. Is there an obvious solution that I am missing?
aaaidan
source share