Giter VIP home page Giter VIP logo

Comments (5)

imbrn avatar imbrn commented on May 29, 2024

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.

maxgalbu avatar maxgalbu commented on May 29, 2024

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.

sbarfurth avatar sbarfurth commented on May 29, 2024

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.

maxgalbu avatar maxgalbu commented on May 29, 2024

What would happen if params.token is integer instead of string? would that result in cause != null?

from v8n.

sbarfurth avatar sbarfurth commented on May 29, 2024

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)

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.