# core-error-predicates

> Error predicate functions for operational errors thrown by node core

Latest version **1.1.0** (published 2015-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install core-error-predicates
pnpm add core-error-predicates
yarn add core-error-predicates
bun add core-error-predicates
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2015-10-27 |
| First published | 2015-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Petka Antonov |
| Maintainers | esailija |
| Keywords | error, errors, patternmatching, dsl |

## Links

- npm: https://www.npmjs.com/package/core-error-predicates
- Repository: https://github.com/petkaantonov/core-error-predicates
- Homepage: https://github.com/petkaantonov/core-error-predicates#readme
- Issues: https://github.com/petkaantonov/core-error-predicates/issues
- npm.io page: https://npm.io/package/core-error-predicates

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2015-10-27
- 1.0.3 — 2015-09-22
- 1.0.2 — 2015-02-23
- 1.0.1 — 2015-01-27
- 1.0.0 — 2015-01-12

## README

#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](https://github.com/petkaantonov/bluebird/blob/master/API.md#catchfunction-errorclassfunction-predicate-function-handler---promise) or in the future when the JavaScript `catch` clauses will be able to take filter/predicate function parameters.

Example using [bluebird](https://github.com/petkaantonov/bluebird/):

```js
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:

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

##Error predicates

 - [`FileNotFoundError`](#filenotfounderror)
 - [`FileAccessError`](#fileaccesserror)
 - [`EOFError`](#eoferror)
 - [`UnknownHostError`](#unknownhosterror)
 - [`SocketError`](#socketerror)
 - [`ProtocolError`](#protocolerror)
 - [`FileSystemError`](#filesystemerror)
 - [`ConnectError`](#connecterror)
 - [`BindError`](#binderror)
 - [`AddressNotFoundError`](#addressnotfounderror)
 - [`NetworkError`](#networkerror)
 - [`SSLError`](#sslerror)

#####`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:</p>

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.

---
_Source: https://npm.io/package/core-error-predicates · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
