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

Exception messages are too vague #1

Closed
BlacKCaT27 opened this issue Nov 1, 2017 · 3 comments
Closed

Exception messages are too vague #1

BlacKCaT27 opened this issue Nov 1, 2017 · 3 comments
Assignees

Comments

@BlacKCaT27
Copy link

First, thanks for writing this. It's a great little tool that does it's job well, and I love the declaritive style.

One issue I wanted to point out though is that the exceptions that are thrown leave much to be desired in terms of usefulness. I'm stuck right now on processing an xml file because I get:

declxml.MissingValue: Missing required element: "name"

In my case, I've deduced that the problem is likely something not being marked as optional that should be and I'm sure I'll track it down shortly, but I had to figure that out on my own. At the VERY least, it would be extremely helpful if the error message explained what the current state of the parser was at the time it found an issue. What node was the parser looking at where it couldn't find an attribute "name"? Or is this an issue with the user_object being passed in not having an attribute called "name"? It's too vague which lead to me having to spend quite a bit of extra time stepping through declxml code to figure out what was going on.

Just a suggestion.

@gatkin
Copy link
Owner

gatkin commented Nov 3, 2017

That is a very good point, I think we can absolutely use the context of the parser's state to provide useful error messages. It can definitely get confusing if you have multiple attributes with the same name to know which one is missing.

@gatkin
Copy link
Owner

gatkin commented Nov 7, 2017

PR #3 should help improve error messages by providing some context information about where we were when the error occurred for both parsing and serialization.

For instance, if we have a processor

books = xml.array(xml.dictionary('book', [
    xml.string('title'),
    xml.integer('year-published')
]), nested='books')

and some XML with a missing field

<books>
    <book>
        <title>I, Robot</title>
        <year-published>1950</year-published>
    </book>
    <book>
        <title>Foundation</title>
    </book>
</books>

We would get the following error when parsing :

MissingValue: Missing required element "year-published" at books>book[1]>year-published

@gatkin
Copy link
Owner

gatkin commented Nov 7, 2017

Definitely let me know if there are more ways error messages can be improved. Thank you for your feedback, I really appreciate it!

@gatkin gatkin closed this as completed Nov 7, 2017
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

2 participants