Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

errify

Basic node-style callback error helper for iced-coffee-script

Build Status Coverage Status Dependency Status devDependency Status Downloads

Originally described by @maxtaco as the "Error Short-Circuiter" pattern:

http://maxtaco.github.io/programming/2014/09/18/handling-errors-in-iced-coffee-script/

NPM

Description

  • Creates a function that runs one function when a callback receives an error as the first argument, and runs a different function when a callback receives a null first argument (the nodejs callback pattern)
  • Flattens nested callbacks
  • Restores sanity

Installation

npm install --save errify

Example

Escape automatically to callback when fs.readFile(...) fails:

nextorigin/express-rendertype/.../src/fancy.coffee#L22

Contrived Example

For readability, I prefer using ideally as the errify keyword. In the spirit of coffee-script it reads like English:

{readDir, readFile} = fs

tryToReadTheFirstFileFrom = (directory, callback) ->
  ideally = errify callback
  await readDir directory, ideally defer files
  [file] = files
  await readFile file, ideally defer contents
  callback null, {files, contents}

ideally = console.error.bind console
folder  = "/path/to/a/list/of/files"

await tryToReadTheFirstFileFrom folder, ideally defer {files, contents}
console.log contents

License

MIT

About

Basic node-style callback error helper for iced-coffee-script

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages