Browse files

use errno's custom.createError() for custom errors

  • Loading branch information...
1 parent e277894 commit 7928da3e35d645984cc94312ff652614041bdb21 @rvagg rvagg committed Dec 26, 2012
Showing with 6 additions and 46 deletions.
  1. +6 −46 lib/errors.js
View
52 lib/errors.js
@@ -30,9 +30,8 @@
* everything in an EnderError type so we can explain the errors better).
*/
-var errno = require('errno')
-
- // Ender Error Types
+var errno = require('errno')
+ , EnderError = errno.custom.createError('EnderError')
, errorTypes = [
'BuildParseError'
, 'UnknownMainError'
@@ -43,50 +42,11 @@ var errno = require('errno')
, 'ChildProcessError'
, 'CompressionError'
, 'MinifyError'
- , 'FilesystemError'
]
-function init (name, message, cause) {
- this.name = name
- // can be passed just a 'cause'
- this.cause = typeof message != 'string' ? message : cause
- this.message = typeof message != 'string' ? message.message : message
-}
-
-// generic prototype, not intended to be actually used - helpful for `instanceof`
-function EnderError (message, cause) {
- Error.call(this)
- Error.captureStackTrace(this, arguments.callee)
- if (message || cause) init.call(this, 'EnderError', message, cause)
-}
-
-EnderError.prototype = new Error()
-
-// Ender error factory
-function createError (name) {
- var err = function (message, cause) {
- init.call(this, name, message, cause)
- if (name == '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)
- Error.captureStackTrace(this, arguments.callee)
- }
- err.prototype = new EnderError()
- return err
-}
-
-// export generic Ender Error
-module.exports.EnderError = EnderError
+module.exports.EnderError = EnderError
+module.exports.FilesystemError = errno.custom.FilesystemError
-// export error types
-errorTypes.forEach(function (type) {
- module.exports[type] = createError(type)
+errorTypes.forEach(function (err) {
+ module.exports[err] = errno.custom.createError(err, EnderError)
})

0 comments on commit 7928da3

Please sign in to comment.