question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to pass error-handlers to a `Validator`-instance

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
prudhveecommented, Jul 21, 2019

Is HumanReadableErrorHandler implemented? Couldn’t find the documentation.

0reactions
funkyfuturecommented, Dec 23, 2015

closing this as the core interface is now available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors & Error Handling - python-cerberus.org
The error handler to be used can be passed as keyword-argument error_handler to the initialization of a validator or by setting it's property...
Read more >
Global error handler for any exception - python - Stack Overflow
I can't use the got_request_exception signal, as it is not allowed to modify the response (http://flask.pocoo.org/docs/0.10/signals/). In contrast all signal ...
Read more >
Error Handlers | MuleSoft Documentation
When a flow is processing a Mule message that raises an error, the normal execution of the flow stops, and the process transfers...
Read more >
Error Handler - Apache Camel
The error handler is scoped as either: CamelContext - Globally in XML or globally only within the same RouteBuilder in Java DSL. Route...
Read more >
Handling Application Errors — Flask Documentation (2.2.x)
An error handler is a function that returns a response when a type of error is raised, ... a “405 Method Not Allowed”...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found