Comments (5)
Hey @maxgalbu
Actually, there's nothing wrong with your code.
The cause
of a ValidationError
is just an Error
instance, that could happen during the validation process. What's happening, in this case, is that you are recursively going to the leaf cause
, and at that level there's no value for the cause in a normal validation process (without excpetions). You can check the https://imbrn.github.io/v8n/api/#validationerror for more details about that.
But in your case, maybe you can use the cause.rule.name
to see what validation rule has failed.
from v8n.
Hi @imbrn,
seeing what validation rule has failed could help, but I'd like to know why it failed, e.g. params
is an integer instead of an object. Something that can help a person in spotting the issue.
The rule could tell me params
should be an object but then i need to go and see the type of params
myself in order to see what's wrong...
from v8n.
While I see what you're saying, @maxgalbu, v8n doesn't actually check that schema
properties are objects. The validation doesn't fail because params
is 1
, but rather because params.tokens
is undefined
.
from v8n.
What would happen if params.token
is integer instead of string? would that result in cause != null
?
from v8n.
Well one of the nested causes you get with that would be this:
...
[
{
"rule": {
"name": "string",
"args": [],
"modifiers": []
},
"value": 1,
"cause": null,
"target": "token"
}
]
...
To explain the above: The cause
here is null
, because this error is not caused by some other error. This error described exactly what went wrong with the target. The target key token was validated using a rule called string
. Its value was 1
. There is no further cause to this, but you are trying to display this error's cause in your function. This is already the root cause. In words: There was an error validating the value 1
for the key 'token' using the string
rule.
So you do get the information that it validated a string with a value of 1
and failed. But that is only one of the reasons it fails. A schema validation works like an interface, as I mentioned in #179, so all the keys defined in it must match whatever validation is given. You don't define any keys as optional
, so validating your large schema against a very small subset of it will cause lots of errors and nested errors. v8n never gives any error messages, it only gives ValidationError
objects, which you can interpret for error messages. If the error above would be the only one, it would be easy to tell that the reason for a failure was an integer for a string validation.
I'm not sure what you're asking for then. You have lots of non-null causes, but the inner most nested causes will always be null, because the root cause obviously doesn't have another cause.
from v8n.
Related Issues (20)
- min() and max() rules in guide HOT 1
- JSON Schema HOT 2
- Version 1.3.0 - v8n().optional() and v8n().string() bug HOT 2
- Bug: nested async rules HOT 1
- Possibility to validate in relation to other rules HOT 4
- Optimise builds depending on consumer capability HOT 5
- Alternating true/false validation on a value HOT 2
- Schema testing against an object that extends the schema HOT 10
- Publish dist folder to git HOT 2
- Can we have a full example for async rules? HOT 2
- Improve support for CI/CD HOT 2
- Improve schema rule with dependent validations and strict mode
- Using optionality and asynchronous rules in the same chain HOT 6
- Logo has bad contrast on GitHub in dark mode HOT 6
- Doumentation does not deploy with GitHub actions
- Security concern HOT 2
- How to properly extend with typescript? HOT 2
- [Question] How to validate value of property against another property? HOT 4
- v8n import typescript - has no call signatures HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v8n.