Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass error-handlers to a Validator-instance #93

Closed
funkyfuture opened this issue May 22, 2015 · 6 comments
Closed

Allow to pass error-handlers to a Validator-instance #93

funkyfuture opened this issue May 22, 2015 · 6 comments
Milestone

Comments

@funkyfuture
Copy link
Member

this is a follow-up to #89 and #90.

i propose to introduce error-handlers in order to allow to deal with errors more flexible.

to achieve that:

  • Validator.__init__ takes an optional error_handler-object
  • Validator._error is extended, so it stores the following data about an error:
    • trail - a list that represents the path to the field in the document (eg: ['a_dict', 'a_list']); a common prefix can be specified upon calling Validator.validate
    • field, value - as of now
    • constraint - the constraint that failed
    • message - a simple error message, like currently implemented
  • Validator.errors calls the format(?)-method of error_handler that may return errors in a desired format and / or do whatever its purpose is

there will be one default-handler and two as reference-implementations:

  • BasicErrorHandler
    • returns errors as now
    • but concentates trail and field
  • HumanReadableErrorHandler
    • is targeted to end-users
    • concentates trail and field
    • suggests valid keys, in case of an unallowed value
    • the index of list-items is increased by one
    • list-items are prefixed with item #
  • YamlErrorHandler
    • structures errors in a dictionary
    • joins it into a yaml-file
@funkyfuture
Copy link
Member Author

i'm willing to implement this, but will complete other TODOs before. any feedback is appreciated.

@CD3
Copy link
Contributor

CD3 commented Jun 17, 2015

I think this is a great idea. I am using YAML to display error messages in my application, it is just a lot simpler to see what the problem is.

@nicolaiarocci
Copy link
Member

Like it. Scheduling for 0.10 release.

@funkyfuture
Copy link
Member Author

i'm currently working on that whenever i have the time and hope to provide a peek on wip this week (next week i'll be abroad).
considering how much unreleased changes currently cumulated and the amount of changes the error-handling will introduce, i'd say it'd be a good idea to postpone this to a 0.11-release.

This was referenced Oct 8, 2015
@funkyfuture
Copy link
Member Author

closing this as the core interface is now available.

@prudhvee
Copy link

Is HumanReadableErrorHandler implemented? Couldn't find the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants