Compare commits

...

3 Commits

@ -20,6 +20,8 @@ Creating and maintaining open-source modules is a lot of work. A donation is als
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".

@ -1,12 +1,19 @@
"use strict";
const createError = require("create-error");
// NOTE: We don't actually inherit from the real Error here, because collecting stacktraces is very expensive and largely useless for our purposes. Validatem's own error reporting is clear enough, and if not, that's a bug in Validatem anyway.
function ValidationError(message, properties) {
this.message = message;
module.exports = createError("ValidationError", {
path: [],
// NOTE: The below are for potential future compatibility logic.
___validatem_isValidationError: true,
___validatem_errorVersion: 1
});
Object.assign(this, {
path: [],
___validatem_isValidationError: true,
___validatem_errorVersion: 1
});
Object.assign(this, properties);
}
ValidationError.prototype.name = "ValidationError";
module.exports = ValidationError;
module.exports.__modulePath = __dirname;

@ -1,11 +1,8 @@
{
"name": "@validatem/error",
"version": "1.0.0",
"version": "1.1.0",
"main": "index.js",
"repository": "http://git.cryto.net/validatem/error.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"dependencies": {
"create-error": "^0.3.1"
}
"license": "WTFPL OR CC0-1.0"
}

Loading…
Cancel
Save