Giter VIP home page Giter VIP logo

Comments (4)

awwright avatar awwright commented on May 12, 2024 1

Ah ok. That might be a good excuse to inherit from Error.

Or, create a separate type of object for the error itself, and it contains a ValidationError instance.

I'll take a look.

from jsonschema.

awwright avatar awwright commented on May 12, 2024

A ValidationError isn't an object that's thrown, it just contains details about a particular problem with your instance. There could be several of them all at once, they're all returned in a ValidatorResult object.

I suppose one might find a reason to throw a ValidationError, is that what you want to do?

Does that answer your question?

from jsonschema.

grindfuk avatar grindfuk commented on May 12, 2024

Oh I see! Thanks for answering so quickly.

The ValidationError is added to the ValidatorResult but if the option {throwError: true} is set, the first
ValidationError is thrown but not as an Error Object. Would it be worth it to add an option to the constructor to initialize it as an object?

var ValidationError = exports.ValidationError = function ValidationError (message, instance, schema, propertyPath, options) {
...
  if (options && options.throwError) {
    Error.call(this, message);
    Error.captureStackTrace(this, ValidationError);
  }
}
...

I'm asking mainly because using promise/deferred methods usually catch instanceof Error. I think I have a custom solution but I thought it would be cool to reach out to you.

I guess that would require prototype to be Error which might do bad things. I shall fork and see.

from jsonschema.

awwright avatar awwright commented on May 12, 2024

I'm going to close this as a duplicate of #264, which should solve this issue. Please drop a comment if there's anything missing in that issue.

from jsonschema.

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.