Git Product home page Git Product logo

Comments (9)

crdoconnor avatar crdoconnor commented on August 10, 2024

Currently YAMLError is what gets raised for normal parsing errors (syntax errors, etc.) whereas StrictYAMLError is what gets raised if your schema doesn't match the input or if you use one of the prohibited features of YAML.

Ideally there should be one root exception for all of this so users of the library can just put one try/except and get a nicely formatted error that clearly describes the issue that they face. This is why I inherit from YAMLError.

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024

Actually that's a good point I should expose ruamel.yaml's YAMLError in strictyaml's init.py.

from strictyaml.

AlexandreDecan avatar AlexandreDecan commented on August 10, 2024

You should preferably not expose the API of ruamel.yaml, and should preferably declare your own exceptions hierarchy, and automatically convert all YAMLError from ruamel.yaml to your own exceptions (of course keep the distinction between errors that are related to YAML and errors that are related to the validation process).

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024

Why?

from strictyaml.

AlexandreDecan avatar AlexandreDecan commented on August 10, 2024

Because your package will look better as a YAML loader with type safety, less as a YAML validator that imposes to load YAML documents through its API and to manipulate it through one of its dependencies.

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024

There's nothing particularly wrong with the way ruamel.yaml loads YAML. It adheres to the spec just fine and it validates what's in the spec just fine and the exceptions it raises are fine. This is why I used it - it's an excellent base to build upon.

strictyaml is not supposed to be a parser in its own right.

from strictyaml.

AlexandreDecan avatar AlexandreDecan commented on August 10, 2024

strictyaml is not supposed to be a parser in its own right.

Currently, it is not possible to:

  • Validate a YAML without loading it with your tool (ala pykwalify).
  • Validate a YAML after it has been loaded by ruamel.yaml or pyyaml (ala https://pypi.python.org/pypi/schema).

So either your provide a feature parity with ruamel.yaml in your load function, or maybe you should not enforce the use of your load function?

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024

It's not, no. The reason for this is because I wanted to ensure that validation errors included line numbers (and in the future, code snippets) - these things would typically be lost if you used another tool to parse first and then passed the result on.

from strictyaml.

AlexandreDecan avatar AlexandreDecan commented on August 10, 2024

I understand, but that means that your validator implies a burden and is not a "drop-in" replacement for ruamel.yaml with a lot of cool stuff about type checking. ;-)

from strictyaml.

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.