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.

structure: how to report path to invalid data element

See original GitHub issue
  • cattrs version: 0.9.0
  • Python version: 3.6.ř
  • Operating System: Debian 9

Description

I want to cattrs to load complex nested data and in case some validation/conversion fails, I want to provide reasonable context information about what part of data did not work properly.

What I Did

Having attrs based classes: Config with attributes source, fetch and publish, each holding value of specific (attrs based) class Source, Fetch and Publish.

If some data element is wrong (e.g. expecting integer and providing string “5a”), the structure process fails raising ValueError("could not convert string to float: '5a'",)

However, the error does not include any contextual information about where in my nested input the problem was read from.

It would be nice to get some sort of path in the exception, which I could use. marshmallow and trafaret are examples of similar solutions providing contextual information.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Tinchecommented, Nov 19, 2020

This is probably the next big feature I work on 😃

2reactions
madsmtmcommented, Jan 24, 2019

We could copy a few ideas from jsonschema, and potentially yield errors iteratively? Or maybe that’s not really in scope, since cattrs need to return the new result.

But have a look at their ValidationError, there’s a few fields there that we could potentially use.

Read more comments on GitHub >

github_iconTop Results From Across the Web

structure: how to report path to invalid data element #47 - GitHub
Having attrs based classes: Config with attributes source, fetch and publish, each holding value of specific (attrs based) class Source, Fetch ...
Read more >
Article: Invalid Data Element: MANDATORY_ELEMENT_EMPTY
This error occurs if you have no map, or you are mapping null data, into an element on an outbound profile, that has...
Read more >
Understanding schema errors | HESA
1) Invalid values​​ This means that it does not conform to the valid entries included in the field descriptions. The XML structure does...
Read more >
invalid - CSS: Cascading Style Sheets - MDN Web Docs
The :invalid CSS pseudo-class represents any , , or other element whose contents fail to validate.
Read more >
MATLAB readstruct - Create structure from file - MathWorks
Select Structure Path ... Specify the precise XML element node under which to start reading the structure in the input file. Read the...
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