How can I lint my Javascript code to identify promise chains (promise.then().then().then()...
) that do not have a fail block at the end? Do any of the existing tools (JSHint, JSLint, the Flow static type checker, Typescript, ...?) allow this?
The motivation for this, candidly, is that sometimes I just forget to put one in code that I write. Then, if an error occurs in that code, it will fail silently and it can be a beast to debug. Instead, it would be better software engineering to be able to catch those errors at lint-time in the same way that I can use linting to identify typos in variable names
For example:
q(this_function_returns_a_promise())
.then(function(data) {
console.log('The promise returned some data: ' + JSON.stringify(data));
})
// .. more thens, spreads, alls
.then(function(modified_data) {
this_function_will_throw_an_error(modified_data);
})
// .. more thens, spreads, alls
.then(function(modified_modified_data) {
console.log('I will not be printed, logging and execution will just stop in ' +
'the middle then()');
});
// if only there was a .fail(function(err) { ... }) here that printed the error!