pax_global_header00006660000000000000000000000064125642624520014522gustar00rootroot0000000000000052 comment=1c2b1fcbf22ef2bafbf6cda378cfed400f5163fd node-errno-0.1.4/000077500000000000000000000000001256426245200135745ustar00rootroot00000000000000node-errno-0.1.4/.gitignore000066400000000000000000000000141256426245200155570ustar00rootroot00000000000000node_modulesnode-errno-0.1.4/.jshintrc000066400000000000000000000021731256426245200154240ustar00rootroot00000000000000{ "predef": [ ] , "bitwise": false , "camelcase": false , "curly": false , "eqeqeq": false , "forin": false , "immed": false , "latedef": false , "noarg": true , "noempty": true , "nonew": true , "plusplus": false , "quotmark": true , "regexp": false , "undef": true , "unused": true , "strict": false , "trailing": true , "maxlen": 120 , "asi": true , "boss": true , "debug": true , "eqnull": true , "esnext": true , "evil": true , "expr": true , "funcscope": false , "globalstrict": false , "iterator": false , "lastsemic": true , "laxbreak": true , "laxcomma": true , "loopfunc": true , "multistr": false , "onecase": false , "proto": false , "regexdash": false , "scripturl": true , "smarttabs": false , "shadow": false , "sub": true , "supernew": false , "validthis": true , "browser": true , "couch": false , "devel": false , "dojo": false , "mootools": false , "node": true , "nonstandard": true , "prototypejs": false , "rhino": false , "worker": true , "wsh": false , "nomen": false , "onevar": false , "passfail": false }node-errno-0.1.4/README.md000066400000000000000000000104771256426245200150640ustar00rootroot00000000000000# node-errno Better [libuv](https://github.com/libuv/libuv)/[Node.js](https://nodejs.org)/[io.js](https://iojs.org) error handling & reporting. Available in npm as *errno*. * [errno exposed](#errnoexposed) * [Custom errors](#customerrors) ## errno exposed Ever find yourself needing more details about Node.js errors? Me too, so *node-errno* contains the errno mappings direct from libuv so you can use them in your code. **By errno:** ```js require('errno').errno[3] // → { // "errno": 3, // "code": "EACCES", // "description": "permission denied" // } ``` **By code:** ```js require('errno').code.ENOTEMPTY // → { // "errno": 53, // "code": "ENOTEMPTY", // "description": "directory not empty" // } ``` **Make your errors more descriptive:** ```js var errno = require('errno') function errmsg(err) { var str = 'Error: ' // if it's a libuv error then get the description from errno if (errno.errno[err.errno]) str += errno.errno[err.errno].description else str += err.message // if it's a `fs` error then it'll have a 'path' property if (err.path) str += ' [' + err.path + ']' return str } var fs = require('fs') fs.readFile('thisisnotarealfile.txt', function (err, data) { if (err) console.log(errmsg(err)) }) ``` **Use as a command line tool:** ``` ~ $ errno 53 { "errno": 53, "code": "ENOTEMPTY", "description": "directory not empty" } ~ $ errno EROFS { "errno": 56, "code": "EROFS", "description": "read-only file system" } ~ $ errno foo No such errno/code: "foo" ``` Supply no arguments for the full list. Error codes are processed case-insensitive. You will need to install with `npm install errno -g` if you want the `errno` command to be available without supplying a full path to the node_modules installation. ## Custom errors Use `errno.custom.createError()` to create custom `Error` objects to throw around in your Node.js library. Create error heirachies so `instanceof` becomes a useful tool in tracking errors. Call-stack is correctly captured at the time you create an instance of the error object, plus a `cause` property will make available the original error object if you pass one in to the constructor. ```js var create = require('errno').custom.createError var MyError = create('MyError') // inherits from Error var SpecificError = create('SpecificError', MyError) // inherits from MyError var OtherError = create('OtherError', MyError) // use them! if (condition) throw new SpecificError('Eeek! Something bad happened') if (err) return callback(new OtherError(err)) ``` Also available is a `errno.custom.FilesystemError` with in-built access to errno properties: ```js fs.readFile('foo', function (err, data) { if (err) return callback(new errno.custom.FilesystemError(err)) // do something else }) ``` The resulting error object passed through the callback will have the following properties: `code`, `errno`, `path` and `message` will contain a descriptive human-readable message. ## Contributors * [bahamas10](https://github.com/bahamas10) (Dave Eddy) - Added CLI * [ralphtheninja](https://github.com/ralphtheninja) (Lars-Magnus Skog) ## Copyright & Licence *Copyright (c) 2012-2015 [Rod Vagg](https://github.com/rvagg) ([@rvagg](https://twitter.com/rvagg))* Made available under the MIT licence: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.node-errno-0.1.4/build.js000077500000000000000000000021631256426245200152360ustar00rootroot00000000000000#!/usr/bin/env node var request = require('request') , fs = require('fs') , uvheadloc = 'https://raw.github.com/joyent/libuv/master/include/uv.h' , defreg = /^\s*XX\(\s*([\-\d]+),\s*([A-Z]+),\s*"([^"]*)"\s*\)\s*\\?$/ request(uvheadloc, function (err, response) { if (err) throw err var data, out data = response.body .split('\n') .map(function (line) { return line.match(defreg) }) .filter(function (match) { return match }) .map(function (match) { return { errno: parseInt(match[1], 10) , code: match[2] , description: match[3] }}) out = 'var all = module.exports.all = ' + JSON.stringify(data, 0, 1) + '\n\n' out += '\nmodule.exports.errno = {\n ' + data.map(function (e, i) { return '\'' + e.errno + '\': all[' + i + ']' }).join('\n , ') + '\n}\n\n' out += '\nmodule.exports.code = {\n ' + data.map(function (e, i) { return '\'' + e.code + '\': all[' + i + ']' }).join('\n , ') + '\n}\n\n' out += '\nmodule.exports.custom = require("./custom")(module.exports)\n' fs.writeFile('errno.js', out) })node-errno-0.1.4/cli.js000077500000000000000000000006501256426245200147050ustar00rootroot00000000000000#!/usr/bin/env node var errno = require('./') , arg = process.argv[2] , data, code if (arg === undefined) return console.log(JSON.stringify(errno.code, null, 2)) if ((code = +arg) == arg) data = errno.errno[code] else data = errno.code[arg] || errno.code[arg.toUpperCase()] if (data) console.log(JSON.stringify(data, null, 2)) else { console.error('No such errno/code: "' + arg + '"') process.exit(1) }node-errno-0.1.4/custom.js000066400000000000000000000031461256426245200154500ustar00rootroot00000000000000var prr = require('prr') function init (type, message, cause) { prr(this, { type : type , name : type // can be passed just a 'cause' , cause : typeof message != 'string' ? message : cause , message : !!message && typeof message != 'string' ? message.message : message }, 'ewr') } // generic prototype, not intended to be actually used - helpful for `instanceof` function CustomError (message, cause) { Error.call(this) if (Error.captureStackTrace) Error.captureStackTrace(this, arguments.callee) init.call(this, 'CustomError', message, cause) } CustomError.prototype = new Error() function createError (errno, type, proto) { var err = function (message, cause) { init.call(this, type, message, cause) //TODO: the specificity here is stupid, errno should be available everywhere if (type == 'FilesystemError') { this.code = this.cause.code this.path = this.cause.path this.errno = this.cause.errno this.message = (errno.errno[this.cause.errno] ? errno.errno[this.cause.errno].description : this.cause.message) + (this.cause.path ? ' [' + this.cause.path + ']' : '') } Error.call(this) if (Error.captureStackTrace) Error.captureStackTrace(this, arguments.callee) } err.prototype = !!proto ? new proto() : new CustomError() return err } module.exports = function (errno) { var ce = function (type, proto) { return createError(errno, type, proto) } return { CustomError : CustomError , FilesystemError : ce('FilesystemError') , createError : ce } } node-errno-0.1.4/errno.js000066400000000000000000000127521256426245200152660ustar00rootroot00000000000000var all = module.exports.all = [ { errno: -2, code: 'ENOENT', description: 'no such file or directory' }, { errno: -1, code: 'UNKNOWN', description: 'unknown error' }, { errno: 0, code: 'OK', description: 'success' }, { errno: 1, code: 'EOF', description: 'end of file' }, { errno: 2, code: 'EADDRINFO', description: 'getaddrinfo error' }, { errno: 3, code: 'EACCES', description: 'permission denied' }, { errno: 4, code: 'EAGAIN', description: 'resource temporarily unavailable' }, { errno: 5, code: 'EADDRINUSE', description: 'address already in use' }, { errno: 6, code: 'EADDRNOTAVAIL', description: 'address not available' }, { errno: 7, code: 'EAFNOSUPPORT', description: 'address family not supported' }, { errno: 8, code: 'EALREADY', description: 'connection already in progress' }, { errno: 9, code: 'EBADF', description: 'bad file descriptor' }, { errno: 10, code: 'EBUSY', description: 'resource busy or locked' }, { errno: 11, code: 'ECONNABORTED', description: 'software caused connection abort' }, { errno: 12, code: 'ECONNREFUSED', description: 'connection refused' }, { errno: 13, code: 'ECONNRESET', description: 'connection reset by peer' }, { errno: 14, code: 'EDESTADDRREQ', description: 'destination address required' }, { errno: 15, code: 'EFAULT', description: 'bad address in system call argument' }, { errno: 16, code: 'EHOSTUNREACH', description: 'host is unreachable' }, { errno: 17, code: 'EINTR', description: 'interrupted system call' }, { errno: 18, code: 'EINVAL', description: 'invalid argument' }, { errno: 19, code: 'EISCONN', description: 'socket is already connected' }, { errno: 20, code: 'EMFILE', description: 'too many open files' }, { errno: 21, code: 'EMSGSIZE', description: 'message too long' }, { errno: 22, code: 'ENETDOWN', description: 'network is down' }, { errno: 23, code: 'ENETUNREACH', description: 'network is unreachable' }, { errno: 24, code: 'ENFILE', description: 'file table overflow' }, { errno: 25, code: 'ENOBUFS', description: 'no buffer space available' }, { errno: 26, code: 'ENOMEM', description: 'not enough memory' }, { errno: 27, code: 'ENOTDIR', description: 'not a directory' }, { errno: 28, code: 'EISDIR', description: 'illegal operation on a directory' }, { errno: 29, code: 'ENONET', description: 'machine is not on the network' }, { errno: 31, code: 'ENOTCONN', description: 'socket is not connected' }, { errno: 32, code: 'ENOTSOCK', description: 'socket operation on non-socket' }, { errno: 33, code: 'ENOTSUP', description: 'operation not supported on socket' }, { errno: 34, code: 'ENOENT', description: 'no such file or directory' }, { errno: 35, code: 'ENOSYS', description: 'function not implemented' }, { errno: 36, code: 'EPIPE', description: 'broken pipe' }, { errno: 37, code: 'EPROTO', description: 'protocol error' }, { errno: 38, code: 'EPROTONOSUPPORT', description: 'protocol not supported' }, { errno: 39, code: 'EPROTOTYPE', description: 'protocol wrong type for socket' }, { errno: 40, code: 'ETIMEDOUT', description: 'connection timed out' }, { errno: 41, code: 'ECHARSET', description: 'invalid Unicode character' }, { errno: 42, code: 'EAIFAMNOSUPPORT', description: 'address family for hostname not supported' }, { errno: 44, code: 'EAISERVICE', description: 'servname not supported for ai_socktype' }, { errno: 45, code: 'EAISOCKTYPE', description: 'ai_socktype not supported' }, { errno: 46, code: 'ESHUTDOWN', description: 'cannot send after transport endpoint shutdown' }, { errno: 47, code: 'EEXIST', description: 'file already exists' }, { errno: 48, code: 'ESRCH', description: 'no such process' }, { errno: 49, code: 'ENAMETOOLONG', description: 'name too long' }, { errno: 50, code: 'EPERM', description: 'operation not permitted' }, { errno: 51, code: 'ELOOP', description: 'too many symbolic links encountered' }, { errno: 52, code: 'EXDEV', description: 'cross-device link not permitted' }, { errno: 53, code: 'ENOTEMPTY', description: 'directory not empty' }, { errno: 54, code: 'ENOSPC', description: 'no space left on device' }, { errno: 55, code: 'EIO', description: 'i/o error' }, { errno: 56, code: 'EROFS', description: 'read-only file system' }, { errno: 57, code: 'ENODEV', description: 'no such device' }, { errno: 58, code: 'ESPIPE', description: 'invalid seek' }, { errno: 59, code: 'ECANCELED', description: 'operation canceled' } ] module.exports.errno = {} module.exports.code = {} all.forEach(function (error) { module.exports.errno[error.errno] = error module.exports.code[error.code] = error }) module.exports.custom = require('./custom')(module.exports) module.exports.create = module.exports.custom.createError node-errno-0.1.4/package.json000066400000000000000000000010521256426245200160600ustar00rootroot00000000000000{ "name": "errno", "authors": [ "Rod Vagg @rvagg (https://github.com/rvagg)" ], "description": "libuv errno details exposed", "keywords": [ "errors", "errno", "libuv" ], "version": "0.1.4", "main": "errno.js", "dependencies": { "prr": "~0.0.0" }, "bin": { "errno": "./cli.js" }, "devDependencies": { "tape": "~3.5.0" }, "repository": { "type": "git", "url": "https://github.com/rvagg/node-errno.git" }, "license": "MIT", "scripts": { "test": "tape test.js" } } node-errno-0.1.4/test.js000077500000000000000000000017441256426245200151220ustar00rootroot00000000000000#!/usr/bin/env node var test = require('tape') , errno = require('./') test('sanity checks', function (t) { t.ok(errno.all, 'errno.all not found') t.ok(errno.errno, 'errno.errno not found') t.ok(errno.code, 'errno.code not found') t.equal(errno.all.length, 59, 'found ' + errno.all.length + ', expected 59') t.equal(errno.errno['-1'], errno.all[0], 'errno -1 not first element') t.equal(errno.code['UNKNOWN'], errno.all[0], 'code UNKNOWN not first element') t.equal(errno.errno[1], errno.all[2], 'errno 1 not third element') t.equal(errno.code['EOF'], errno.all[2], 'code EOF not third element') t.end() }) test('custom errors', function (t) { var Cust = errno.create('FooNotBarError') var cust = new Cust('foo is not bar') t.equal(cust.name, 'FooNotBarError', 'correct custom name') t.equal(cust.type, 'FooNotBarError', 'correct custom type') t.equal(cust.message, 'foo is not bar', 'correct custom message') t.notOk(cust.cause, 'no cause') t.end() })