Sha256: 2d0ae7f9b78ccfdb124eab53ee62ff497ba70061e3846427658d1e8a9e5723ea

Contents?: true

Size: 1.62 KB

Versions: 37

Compression:

Stored size: 1.62 KB

Contents

var prr = require('prr')

function init (type, message, cause) {
  if (!!message && typeof message != 'string') {
    message = message.message || message.name
  }
  prr(this, {
      type    : type
    , name    : type
      // can be passed just a 'cause'
    , cause   : typeof message != 'string' ? message : cause
    , 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, this.constructor)
  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, err)
  }
  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
  }
}

Version data entries

37 entries across 36 versions & 12 rubygems

Version Path
rapid_stack-0.2.0 templates/frontend/node_modules/errno/custom.js
rapid_stack-0.1.1 templates/FrontEnd/node_modules/errno/custom.js
rapid_stack-0.1.0 templates/FrontEnd/node_modules/errno/custom.js
optimacms-0.1.61 spec/dummy/node_modules/errno/custom.js
disco_app-0.18.0 test/dummy/node_modules/errno/custom.js
disco_app-0.18.2 test/dummy/node_modules/errno/custom.js
disco_app-0.16.1 test/dummy/node_modules/errno/custom.js
disco_app-0.15.2 test/dummy/node_modules/errno/custom.js
disco_app-0.18.4 test/dummy/node_modules/errno/custom.js
disco_app-0.18.1 test/dummy/node_modules/errno/custom.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/errno/custom.js
disco_app-0.14.0 test/dummy/node_modules/errno/custom.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/errno/custom.js
tang-0.2.1 spec/tang_app/node_modules/errno/custom.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/errno/custom.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/errno/custom.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/errno/custom.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/errno/custom.js
tang-0.2.0 spec/tang_app/node_modules/errno/custom.js
tang-0.1.0 spec/tang_app/node_modules/errno/custom.js