bluebird: second argument for .tap or similar method for rejections

I often use .tap(console.log) for quick debugging. It would be useful for me to have it either work like .then so I could do .tap(null, console.log) as well to log rejections. Or to have a similar method that works like .tap but is analog to .catch as in .tapRejection(console.log).

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 31 (7 by maintainers)

Most upvoted comments

I’ve also got a legitimate production usecase: maintaining the lifecycle of a transaction for running sql queries.

Currently I have to do this:

var transaction = sql.transaction()
return action1(transaction)
  .then(() => action2(transaction))
  .then(transaction.commit)
  .catch(function (error) {
    transaction.rollback()
    return Promise.reject(error)
  })

I would prefer to do this:

var transaction = sql.transaction()
return action1(transaction)
  .then(() => action2(transaction))
  .then(transaction.commit)
  .tap(null, transaction.rollback)

Of course, a tapError function would be even better.

You said you get 100+ exceptions / second, that only makes sense if it’s production.

@spion to be fair that same argument can be made for tap:

function log(val){
   console.log(val);
    return val;
}

.then(log)

So if I’m getting this right: you are editing code in production to add a quick console.log, instead of logging all exceptions automatically and just grepping your function name from them? And you want bluebird to endorse this practice by adding a feature into the core which makes an anti-pattern take 1 line instead of 3?