Socket
Socket
Sign inDemoInstall

core-error-predicates

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

core-error-predicates

Error predicate functions for operational errors thrown by node core


Version published
Weekly downloads
107
increased by2.88%
Maintainers
1
Weekly downloads
 
Created
Source

#Installation

npm install core-error-predicates

#Introduction

Error predicate functions for operational errors thrown by node core.

Predicate functions take an error object as argument and return true if the error object matches. This useful for instance when using bluebird catch filters or in the future when the JavaScript catch clauses will be able to take filter/predicate function parameters.

Example using bluebird:

require("core-error-predicates").globalize();
fs.readFileAsync("test.txt", "utf8").then(function(contents) {
    console.log("file contents:", contents);
})
.catch(FileNotFoundError, function(e) {
    console.log("file test.txt does not exist");
})
.catch(FileAccessError, function(e) {
    console.log("no permissions to access test.txt");
});

#API

The module exports various error predicates and the .globalize() method.

The .globalize() method makes all the predicate functions available in global scope for convenience. If the name is already taken for a predicate in global scope, it will not be overwritten.

##Error predicates

#####FileNotFoundError

When the error's code matches one of:

  • ENOENT

#####FileAccessError

When the error's code matches one of:

  • EACCESS
  • EPERM

#####EOFError

When the error's code matches one of:

  • EOF

#####UnknownHostError

When the error's code matches one of:

  • EADDRINFO

#####SocketError

When the error's code matches one of:

  • EISCONN
  • ENOTCONN
  • ENOTSOCK
  • ENOTSUP
  • EPROTOTYPE
  • EAIFAMNOSUPPORT
  • EAISERVICE

#####ProtocolError

When the error's code matches one of:

  • EPROTO
  • EPROTONOSUPPORT
  • EPROTOTYPE

#####FileSystemError

When the error's code matches one of:

  • EBUSY
  • ENOENT
  • EOF
  • EACCESS
  • EAGAIN
  • EBADF
  • EMFILE
  • ENOTDIR
  • EISDIR
  • EEXIST
  • ENAMETOOLONG
  • EPERM
  • ELOOP
  • ENOTEMPTY
  • ENOSPC
  • EIO
  • EROFS
  • ENODEV
  • ESPIPE
  • ECANCELED
  • ENFILE
  • EXDEV

#####NetworkError

When the error's code matches one of:

  • EADDRINFO
  • EADDRNOTAVAIL
  • EAFNOSUPPORT
  • EALREADY
  • ECONNABORTED
  • ECONNREFUSED
  • ECONNRESET
  • EDESTADDRREQ
  • EHOSTUNREACH
  • EISCONN
  • EMSGSIZE
  • ENETDOWN
  • ENETUNREACH
  • ENONET
  • ENOTCONN
  • ENOTSOCK
  • ENOTSUP
  • EPIPE
  • EPROTO
  • EPROTONOSUPPORT
  • EPROTOTYPE
  • ETIMEDOUT
  • EAIFAMNOSUPPORT
  • EAISERVICE
  • EAISOCKTYPE
  • ESHUTDOWN

#####SSLError

When the error's message begins with -SSL Error:`

Keywords

FAQs

Package last updated on 12 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc