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.

Reference to location within data in SchemaError

See original GitHub issue

I would like SchemaError to tell me where in the data structure the error occurred.

Something like:

# Schema:
Schema({
    'key1': {
        'child1': {
            'child2': [
                {'pedo': bool}
            ]
        }
    },
    Optional('key2'): {
        'foo': str
    }
})

# Data:
{
    'key1': {
        'child1': {
            'child2': [
                {'pedo': 1},
                {'pedo': false},
            ]
        }
    }
}

# Error message:
{
    'key1': {
        'child1': {
            'child2': {
                0: {'pedo': 'this value should be an instance of bool not int'}
            }
        }
    }
}

# Or as a list:
['key1', 'child1', 'child2', 0, 'pedo']

This way I would be able to find the location of the error in my parsed YAML file. It’s also just a lot more helpful error message. Something like 1 should be bool tells me almost nothing.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:6
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
danielmaxxcommented, Nov 18, 2015

I agree. The current message is quite useless. Having a simple list with the path to the error would be super helpful.

0reactions
kurtbrosecommented, Jan 13, 2017

looks like this may be handled recently by this: https://github.com/keleshev/schema/commit/61cc0bf84dd3efc830a366fb200c386bae35c243

Here’s the behavior on your example:

>>> # Schema:
... Schema({
...     'key1': {
...         'child1': {
...             'child2': [
...                 {'pedo': bool}
...             ]
...         }
...     },
...     Optional('key2'): {
...         'foo': str
...     }
... }).validate(
... # Data:
... {
...     'key1': {
...         'child1': {
...             'child2': [
...                 {'pedo': 1},
...                 {'pedo': False},
...             ]
...         }
...     }
... })
Traceback (most recent call last):
  File "<stdin>", line 20, in <module>
  File "/Users/kurtrose/schema/schema.py", line 244, in validate
    raise SchemaError([k] + x.autos, [e] + x.errors)
schema.SchemaError: Key 'key1' error:
Key 'child1' error:
Key 'child2' error:
Or({'pedo': <type 'bool'>}) did not validate {'pedo': 1}
Key 'pedo' error:
1 should be instance of 'bool'
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I fix "Can't resolve reference" error when referencing ...
2 Answers 2 · The reference is inside the same file. I can also read the documentation for ajv. But what is wrong...
Read more >
Understanding schema errors | HESA
Schema errors are designed to give as much location information as possible but the amount of information displayed will depend on how far...
Read more >
Schema error on slick_entityreference_vanilla formatter [#2997165 ...
Problem/Motivation The slick_entityreference_vanilla formatter doesn't have any schema. However, the module provides schema for a non-exisiting ...
Read more >
Specifying a schema | BigQuery - Google Cloud
BigQuery lets you specify a table's schema when you load data into a table, and when you create an empty table. Alternatively, you...
Read more >
Introduction to Schema: A Python Libary to Validate your Data
What if we want to determine whether the data within a column satisfies a specific condition that is not relevant to data types...
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