# @validatem/error

> This package contains the `ValidationError` type for [`validatem`](https://www.npmjs.com/package/@validatem/core).

Latest version **1.1.0** (published 2020-07-03) · WTFPL OR CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install @validatem/error
pnpm add @validatem/error
yarn add @validatem/error
bun add @validatem/error
```

## 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 | 2020-07-03 |
| First published | 2020-04-20 |
| Weekly downloads | 0 |
| License | WTFPL OR CC0-1.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sven Slootweg |
| Maintainers | joepie91 |

## Links

- npm: https://www.npmjs.com/package/@validatem/error
- Repository: http://git.cryto.net/validatem/error
- npm.io page: https://npm.io/package/@validatem/error

## Recent versions

- 1.1.0 (latest) — 2020-07-03
- 1.0.0 — 2020-04-20

## README

# @validatem/error

This package contains the `ValidationError` type for [`validatem`](https://www.npmjs.com/package/@validatem/core).

__A VERY IMPORTANT NOTE:__ You should *always* use the caret notation (eg. `^1.0.0`) when depending on this package. NPM and Yarn will do this by default when you `npm install @validatem/error` or `yarn add @validatem/error`, but some people turn this off - don't do that here, or things might break!

## Why is this a separate package?

Because it makes forwards compatibility easier. Even if [`@validatem/core`](https://www.npmjs.com/package/@validatem/core) ever needs a breaking release, chances are that the error format remains unchanged. Making the error type separately versionable, means that in that scenario validators should stay compatible with both the old *and* the new version of the core, without validator authors needing to update anything.

## License, donations, and other boilerplate

Licensed under either the [WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), at your choice. In practice, that means it's more or less public domain, and you can do whatever you want with it. Giving credit is *not* required, but still very much appreciated! I'd love to [hear from you](mailto:admin@cryto.net) if `validatem` was useful to you.

Creating and maintaining open-source modules is a lot of work. A donation is also not required, but much appreciated! You can donate [here](http://cryto.net/~joepie91/donate.html).

## API

### new ValidationError(message, [properties])

The constructor for `validatem`'s `ValidationError` type. This is invoked like any other `Error` constructor, but you may optionally pass extra metadata that should be stored on the error.

__Note that, for performance reasons (preventing stacktrace collection), the returned object does not *actually* inherit from `Error`!__ This should not affect its correct functioning, considering that the stacktraces of individual validators are not used in Validatem, and `ValidationError`s should never be thrown outside of a validator context anyway.

__Unless you are implementing a parser and using virtual properties, you probably do not need to specify the `path` property.__ Combinators like `arrayOf` will insert their path segments after-the-fact by themselves, your validator does not need to do this.

* __message:__ A description of the validation problem. This should be formatted in such a way that it describes the *requirement*, and *not* how it failed; for example, it should say "Must be a string" rather than "Is not a string".
* __properties:__ *Optional.* An object of properties to attach to the new error object.
	* __path:__ An array of 'path segment' strings that describes the location of the validation error. 

## Changelog

### v1.0.0 (April 20, 2020)

Initial release.

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