• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Delegates to `succ` on sucecss or to `fail` on error
2# ex: Thing.load 123, iferr cb, (thing) -> ...
3iferr = (fail, succ) -> (err, a...) ->
4  if err? then fail err
5  else succ? a...
6
7# Like iferr, but also catches errors thrown from `succ` and passes to `fail`
8tiferr = (fail, succ) -> iferr fail, (a...) ->
9  try succ a...
10  catch err then fail err
11
12# Delegate to the success function on success, or throw the error otherwise
13# ex: Thing.load 123, throwerr (thing) -> ...
14throwerr = iferr.bind null, (err) -> throw err
15
16# Prints errors when one is passed, or does nothing otherwise
17# ex: thing.save printerr
18printerr = iferr (err) -> console.error err.stack or err
19
20module.exports = exports = iferr
21exports.iferr = iferr
22exports.tiferr = tiferr
23exports.throwerr = throwerr
24exports.printerr = printerr
25