var errors = {};
[
  /**
   * node.js errors
   */
  '-1:UNKNOWN:unknown error',
  '0:OK:success',
  '1:EOF:end of file',
  '2:EADDRINFO:getaddrinfo error',
  '3:EACCES:permission denied',
  '4:EAGAIN:resource temporarily unavailable',
  '5:EADDRINUSE:address already in use',
  '6:EADDRNOTAVAIL:address not available',
  '7:EAFNOSUPPORT:address family not supported',
  '8:EALREADY:connection already in progress',
  '9:EBADF:bad file descriptor',
  '10:EBUSY:resource busy or locked',
  '11:ECONNABORTED:software caused connection abort',
  '12:ECONNREFUSED:connection refused',
  '13:ECONNRESET:connection reset by peer',
  '14:EDESTADDRREQ:destination address required',
  '15:EFAULT:bad address in system call argument',
  '16:EHOSTUNREACH:host is unreachable',
  '17:EINTR:interrupted system call',
  '18:EINVAL:invalid argument',
  '19:EISCONN:socket is already connected',
  '20:EMFILE:too many open files',
  '21:EMSGSIZE:message too long',
  '22:ENETDOWN:network is down',
  '23:ENETUNREACH:network is unreachable',
  '24:ENFILE:file table overflow',
  '25:ENOBUFS:no buffer space available',
  '26:ENOMEM:not enough memory',
  '27:ENOTDIR:not a directory',
  '28:EISDIR:illegal operation on a directory',
  '29:ENONET:machine is not on the network',
  // errno 30 skipped, as per https://github.com/rvagg/node-errno/blob/master/errno.js
  '31:ENOTCONN:socket is not connected',
  '32:ENOTSOCK:socket operation on non-socket',
  '33:ENOTSUP:operation not supported on socket',
  '34:ENOENT:no such file or directory',
  '35:ENOSYS:function not implemented',
  '36:EPIPE:broken pipe',
  '37:EPROTO:protocol error',
  '38:EPROTONOSUPPORT:protocol not supported',
  '39:EPROTOTYPE:protocol wrong type for socket',
  '40:ETIMEDOUT:connection timed out',
  '41:ECHARSET:invalid Unicode character',
  '42:EAIFAMNOSUPPORT:address family for hostname not supported',
  // errno 43 skipped, as per https://github.com/rvagg/node-errno/blob/master/errno.js
  '44:EAISERVICE:servname not supported for ai_socktype',
  '45:EAISOCKTYPE:ai_socktype not supported',
  '46:ESHUTDOWN:cannot send after transport endpoint shutdown',
  '47:EEXIST:file already exists',
  '48:ESRCH:no such process',
  '49:ENAMETOOLONG:name too long',
  '50:EPERM:operation not permitted',
  '51:ELOOP:too many symbolic links encountered',
  '52:EXDEV:cross-device link not permitted',
  '53:ENOTEMPTY:directory not empty',
  '54:ENOSPC:no space left on device',
  '55:EIO:i/o error',
  '56:EROFS:read-only file system',
  '57:ENODEV:no such device',
  '58:ESPIPE:invalid seek',
  '59:ECANCELED:operation canceled',

  /**
   * Filer specific errors
   */
  '1000:ENOTMOUNTED:not mounted',
  '1001:EFILESYSTEMERROR:missing super node, use \'FORMAT\' flag to format filesystem.',
  '1002:ENOATTR:attribute does not exist'
].forEach(function(e) {
  e = e.split(':');
  var errno = e[0],
      err = e[1],
      message = e[2];

  function ctor(m) {
    this.message = m || message;
  }
  var proto = ctor.prototype = new Error();
  proto.errno = errno;
  proto.code = err;
  proto.constructor = ctor;

  // We expose the error as both Errors.EINVAL and Errors[18]
  errors[err] = errors[errno] = ctor;
});

module.exports = errors;
