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

Add new exception ExtraItemsError #241

Merged
merged 1 commit into from
Jan 16, 2016
Merged

Add new exception ExtraItemsError #241

merged 1 commit into from
Jan 16, 2016

Conversation

surabujin
Copy link
Contributor

This allow caller to analise errors from extra fields programmatically.
Without this error type to know which fields treated as "extra" caller
must parse error string.

class ExtraItemsError(Invalid):
def __init__(self, node, extras, msg=None):
if msg is None:
msg = _('Unrecognized items')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can fix the coverage failure by moving the _('Unrecognize items') into the function signature itself. E.g.:

class ExtraItemsError(Invalid):
    def __init__(self, node, extras, msg=_('Unrecognized items')):
        super(ExtraItemsError, self).__init__(node, msg)
        self.extras = extras

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it will be evaluated on module import time. Is it not too early? I think many program make message translation configuration on more later stage.

@tseaver
Copy link
Member

tseaver commented Sep 10, 2015

LGTM, assuming the coverage failure is fixed.

@mmerickel
Copy link
Member

This needs docs updated and a changelog entry.

For example

- ``raise`` will cause a :exc:`colander.Invalid` exception to
. However it needs to be rendered into the api docs as well.

Also please add your name to CONTRIBUTORS.txt.

This allow caller to analise errors from extra fields programmatically.
Without this error type to know which fields treated as "extra" caller
must parse error string.
@surabujin
Copy link
Contributor Author

Is it ok now?

)
raise ExtraItemsError(
node, value,
msg=_('Unrecognized keys in mapping: "${val}"',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Unknown looks more appropriate than Unrecognized

@leplatrem
Copy link

Great and useful feature!

I had troubles understanding the name of the exception. Couldn't we find something with Unknown in the name? Like UnknownKeyErrror?

@surabujin
Copy link
Contributor Author

As for me, UnknownKeyError is too common. But I don't insist on my variant, so it up to community.

@tisdall
Copy link
Contributor

tisdall commented Sep 14, 2015

In case anyone else is thinking the same thing I first thought...

When I first saw this I thought "what's the point?". If you get random keys you didn't expect then there's not really any way to recover from that so just throw the exception and be done with it. And while that's still true, what @surabujin is trying to do is make the exception into a format that can be transformed into errors that conform to some convention in other libraries. Specifically, he's trying to throw Cornice JSON errors that outline more specifically where an error occurred in the REST service (if I'm understanding his PR to Cornice properly).

@surabujin
Copy link
Contributor Author

@tisdall yep - you understand everything right. I will need some more changes to colander, if this and cornice PR will be approved.

@lmctv
Copy link
Contributor

lmctv commented Jan 16, 2016

Some bikeshedding, since another conflict-resolving merge is needed... why not UnexpectedItemError ?

@mmerickel
Copy link
Member

I'm going to rename this to UnknownItemsError as it maps better to the unknown='raise' option to Mapping(). Similarly instead of error.extras it'll be error.unknown_items. Otherwise LGTM.

@mmerickel
Copy link
Member

Changed my mind for the last time. Error will be UnsupportedFields with a fields attribute.

@lmctv
Copy link
Contributor

lmctv commented Jan 16, 2016

+1 for UnsupportedFields!

@mmerickel mmerickel merged commit 465122e into Pylons:master Jan 16, 2016
mmerickel added a commit that referenced this pull request Jan 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants