Giter Club home page Giter Club logo

core-error-predicates's Introduction

#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.

Predicates can be turned into instances of their error types by using the new operator:

try {
  throw new FileNotFoundError("A file was not found!");
}
catch (e) {
  assert(FileNotFoundError(e) === true);
}

##Error predicates

#####FileNotFoundError

When the error's code matches one of:

  • ENOENT

#####FileAccessError

When the error's code matches one of:

  • EACCES
  • 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
  • EACCES
  • EAGAIN
  • EBADF
  • EMFILE
  • ENOTDIR
  • EISDIR
  • EEXIST
  • ENAMETOOLONG
  • EPERM
  • ELOOP
  • ENOTEMPTY
  • ENOSPC
  • EIO
  • EROFS
  • ENODEV
  • ESPIPE
  • ECANCELED
  • ENFILE
  • EXDEV

#####ConnectError

When the error's code matches one of:

  • ECONNABORTED
  • ECONNREFUSED
  • ECONNRESET
  • ETIMEDOUT

#####BindError

When the error's code matches one of:

  • EADDRNOTAVAIL

#####AddressNotFoundError

When the error's code matches one of:

  • ENOTFOUND

#####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
  • ENOTFOUND

#####SSLError

When the error's message begins with "SSL Error:".

#License

The MIT License (MIT)

Copyright (c) 2015 Petka Antonov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

core-error-predicates's People

Contributors

petkaantonov avatar phpnode avatar tjconcept avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.