aboutsummaryrefslogtreecommitdiff
path: root/node_modules/errno/custom.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/errno/custom.js')
-rw-r--r--node_modules/errno/custom.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/node_modules/errno/custom.js b/node_modules/errno/custom.js
new file mode 100644
index 000000000..7be16c1e4
--- /dev/null
+++ b/node_modules/errno/custom.js
@@ -0,0 +1,55 @@
+var 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
+ }
+}