[Pkg-javascript-commits] [node-errno] 01/04: New upstream version 0.1.4
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Thu May 4 09:39:21 UTC 2017
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-errno.
commit caec4b3440a8286ca76c79bf49a203b197c2bc87
Author: Pirate Praveen <praveen at debian.org>
Date: Thu May 4 15:01:28 2017 +0530
New upstream version 0.1.4
---
README.md | 42 ++--
errno.js | 730 +++++++++++++++++++++++++----------------------------------
package.json | 6 +-
test.js | 37 +--
4 files changed, 353 insertions(+), 462 deletions(-)
diff --git a/README.md b/README.md
index 52bd10d..2c1f8a5 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# node-errno
-Better [libuv](https://github.com/joyent/libuv)/[Node.js](http://nodejs.org) error handling & reporting. Available in npm as *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)
@@ -38,26 +38,25 @@ require('errno').code.ENOTEMPTY
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 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)
- return console.log(errmsg(err))
+ if (err)
+ console.log(errmsg(err))
})
```
@@ -90,10 +89,10 @@ You will need to install with `npm install errno -g` if you want the `errno` com
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 errno = require('errno')
-var MyError = errno.custom.createError('MyError') // inherits from Error
-var SpecificError = errno.custom.createError('SpecificError', MyError) // inherits from MyError
-var OtherError = errno.custom.createError('OtherError', MyError)
+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')
@@ -115,10 +114,11 @@ The resulting error object passed through the callback will have the following p
## Contributors
* [bahamas10](https://github.com/bahamas10) (Dave Eddy) - Added CLI
+* [ralphtheninja](https://github.com/ralphtheninja) (Lars-Magnus Skog)
## Copyright & Licence
-*Copyright (c) 2012 [Rod Vagg](https://github.com/rvagg) ([@rvagg](https://twitter.com/rvagg))*
+*Copyright (c) 2012-2015 [Rod Vagg](https://github.com/rvagg) ([@rvagg](https://twitter.com/rvagg))*
Made available under the MIT licence:
diff --git a/errno.js b/errno.js
index 8cd1646..efb79d4 100644
--- a/errno.js
+++ b/errno.js
@@ -1,427 +1,313 @@
var all = module.exports.all = [
- {
- "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"
- }
+ {
+ 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 = {}
-module.exports.errno = {
- '-1': all[0]
- , '0': all[1]
- , '1': all[2]
- , '2': all[3]
- , '3': all[4]
- , '4': all[5]
- , '5': all[6]
- , '6': all[7]
- , '7': all[8]
- , '8': all[9]
- , '9': all[10]
- , '10': all[11]
- , '11': all[12]
- , '12': all[13]
- , '13': all[14]
- , '14': all[15]
- , '15': all[16]
- , '16': all[17]
- , '17': all[18]
- , '18': all[19]
- , '19': all[20]
- , '20': all[21]
- , '21': all[22]
- , '22': all[23]
- , '23': all[24]
- , '24': all[25]
- , '25': all[26]
- , '26': all[27]
- , '27': all[28]
- , '28': all[29]
- , '29': all[30]
- , '31': all[31]
- , '32': all[32]
- , '33': all[33]
- , '34': all[34]
- , '35': all[35]
- , '36': all[36]
- , '37': all[37]
- , '38': all[38]
- , '39': all[39]
- , '40': all[40]
- , '41': all[41]
- , '42': all[42]
- , '44': all[43]
- , '45': all[44]
- , '46': all[45]
- , '47': all[46]
- , '48': all[47]
- , '49': all[48]
- , '50': all[49]
- , '51': all[50]
- , '52': all[51]
- , '53': all[52]
- , '54': all[53]
- , '55': all[54]
- , '56': all[55]
- , '57': all[56]
- , '58': all[57]
- , '59': all[58]
-}
+all.forEach(function (error) {
+ module.exports.errno[error.errno] = error
+ module.exports.code[error.code] = error
+})
-
-module.exports.code = {
- 'UNKNOWN': all[0]
- , 'OK': all[1]
- , 'EOF': all[2]
- , 'EADDRINFO': all[3]
- , 'EACCES': all[4]
- , 'EAGAIN': all[5]
- , 'EADDRINUSE': all[6]
- , 'EADDRNOTAVAIL': all[7]
- , 'EAFNOSUPPORT': all[8]
- , 'EALREADY': all[9]
- , 'EBADF': all[10]
- , 'EBUSY': all[11]
- , 'ECONNABORTED': all[12]
- , 'ECONNREFUSED': all[13]
- , 'ECONNRESET': all[14]
- , 'EDESTADDRREQ': all[15]
- , 'EFAULT': all[16]
- , 'EHOSTUNREACH': all[17]
- , 'EINTR': all[18]
- , 'EINVAL': all[19]
- , 'EISCONN': all[20]
- , 'EMFILE': all[21]
- , 'EMSGSIZE': all[22]
- , 'ENETDOWN': all[23]
- , 'ENETUNREACH': all[24]
- , 'ENFILE': all[25]
- , 'ENOBUFS': all[26]
- , 'ENOMEM': all[27]
- , 'ENOTDIR': all[28]
- , 'EISDIR': all[29]
- , 'ENONET': all[30]
- , 'ENOTCONN': all[31]
- , 'ENOTSOCK': all[32]
- , 'ENOTSUP': all[33]
- , 'ENOENT': all[34]
- , 'ENOSYS': all[35]
- , 'EPIPE': all[36]
- , 'EPROTO': all[37]
- , 'EPROTONOSUPPORT': all[38]
- , 'EPROTOTYPE': all[39]
- , 'ETIMEDOUT': all[40]
- , 'ECHARSET': all[41]
- , 'EAIFAMNOSUPPORT': all[42]
- , 'EAISERVICE': all[43]
- , 'EAISOCKTYPE': all[44]
- , 'ESHUTDOWN': all[45]
- , 'EEXIST': all[46]
- , 'ESRCH': all[47]
- , 'ENAMETOOLONG': all[48]
- , 'EPERM': all[49]
- , 'ELOOP': all[50]
- , 'EXDEV': all[51]
- , 'ENOTEMPTY': all[52]
- , 'ENOSPC': all[53]
- , 'EIO': all[54]
- , 'EROFS': all[55]
- , 'ENODEV': all[56]
- , 'ESPIPE': all[57]
- , 'ECANCELED': all[58]
-}
-
-
-module.exports.custom = require("./custom")(module.exports)
-module.exports.create = module.exports.custom.createError
\ No newline at end of file
+module.exports.custom = require('./custom')(module.exports)
+module.exports.create = module.exports.custom.createError
diff --git a/package.json b/package.json
index be656b9..fe877cb 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
"errno",
"libuv"
],
- "version": "0.1.1",
+ "version": "0.1.4",
"main": "errno.js",
"dependencies": {
"prr": "~0.0.0"
@@ -18,7 +18,7 @@
"errno": "./cli.js"
},
"devDependencies": {
- "request": "*"
+ "tape": "~3.5.0"
},
"repository": {
"type": "git",
@@ -26,6 +26,6 @@
},
"license": "MIT",
"scripts": {
- "test": "node ./test.js"
+ "test": "tape test.js"
}
}
diff --git a/test.js b/test.js
index 818321d..6b76a85 100755
--- a/test.js
+++ b/test.js
@@ -1,26 +1,31 @@
#!/usr/bin/env node
-var assert = require('assert')
+var test = require('tape')
, errno = require('./')
-assert(errno.all, 'errno.all not found')
-assert(errno.errno, 'errno.errno not found')
-assert(errno.code, 'errno.code not found')
+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')
-assert(errno.all.length === 59, 'found ' + errno.all.length + ', expected 59')
+ 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')
-assert(errno.errno['-1'] === errno.all[0], 'errno -1 not first element')
+ t.equal(errno.code['UNKNOWN'], errno.all[0], 'code UNKNOWN not first element')
-assert(errno.code['UNKNOWN'] === errno.all[0], 'code UNKNOWN not first element')
+ t.equal(errno.errno[1], errno.all[2], 'errno 1 not third element')
-assert(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()
+})
-assert(errno.code['EOF'] === errno.all[2], 'code EOF not third element')
+test('custom errors', function (t) {
+ var Cust = errno.create('FooNotBarError')
+ var cust = new Cust('foo is not bar')
-var Cust = errno.create('FooNotBarError')
-var cust = new Cust('foo is not bar')
-
-assert(cust.name == 'FooNotBarError', 'correct custom name')
-assert(cust.type == 'FooNotBarError', 'correct custom type')
-assert(cust.message == 'foo is not bar', 'correct custom message')
-assert(!cust.cause, 'no cause')
\ No newline at end of file
+ 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()
+})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-errno.git
More information about the Pkg-javascript-commits
mailing list