Skip to content

Instantly share code, notes, and snippets.

@jandre
Last active August 29, 2015 14:01
Show Gist options
  • Save jandre/f4c39e101c622d9f0eeb to your computer and use it in GitHub Desktop.
Save jandre/f4c39e101c622d9f0eeb to your computer and use it in GitHub Desktop.
really node???
//
// async method passing errors via
// the standard convention of callback(err)
//
> dns.reverse('4.4.4.4', console.log)
{ oncomplete: [Function: onanswer] }
> { [Error: getHostByAddr ENOTFOUND]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getHostByAddr' }

//
// but wait! it also throws exceptions!
// 
> dns.reverse('boobs.com', console.log)
Error: getHostByAddr ENOTIMP
    at errnoException (dns.js:37:11)
    at Object.query [as reverse] (dns.js:156:13)
    at repl:1:6
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)


//
// so you have to write code like this???
// which leads duplicate error handling plus 
// awesome stacktraces, btw, if your callback happens to throw an exception
//
> try { 
   dns.reverse('asdfasdf', console.log); 
} catch (err) { console.error("SERIOUSLY NODE???", err); }
SERIOUSLY NODE??? { [Error: getHostByAddr ENOTIMP] code: 'ENOTIMP', errno: 'ENOTIMP', syscall: 'getHostByAddr' }

Yes there is an open issue: nodejs/node-v0.x-archive#6505

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment