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

Exceptions could use some named attributes #65

Closed
jamadden opened this issue Sep 10, 2018 · 0 comments
Closed

Exceptions could use some named attributes #65

jamadden opened this issue Sep 10, 2018 · 0 comments

Comments

@jamadden
Copy link
Member

In our validation code using zope.schema fields, we have lots of things that look like this:

try:
    field.validate(value)
except WrongContainedType as e:
    if e.args and all(isinstance(SchemaNotProvided, v) for v in e.args[0]):
        # try to adapt
except WrongType as e:
    if len(e.args) == 3:
         expected_type = e.args[1]
          # try to adapt
except TooLong as e:
    if len(e.args) == 2:
        max_size = e.args[1]
        # Produce a pretty error message

All this argument parsing feels fragile.

With named attributes, we could document what exceptions are expected to have. We could use keyword arguments (with defaults) in the constructors to maintain compatibility with code that raises bare exceptions or uses different arguments.

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

1 participant