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

Reference values in error messages. #4

Open
apalala opened this issue Oct 15, 2012 · 5 comments
Open

Reference values in error messages. #4

apalala opened this issue Oct 15, 2012 · 5 comments

Comments

@apalala
Copy link

apalala commented Oct 15, 2012

It would be good if the user-provided values could be referenced in error messages:

schema = Schema( {'<file>': [And(os.path.isfile, error='File "{value}" does not exist')]
                                  ...
@keleshev
Copy link
Owner

That looks like a useful proposal.

Rogdham added a commit to Rogdham/schema that referenced this issue May 13, 2013
@Rogdham
Copy link
Contributor

Rogdham commented May 13, 2013

Ok, here is my patch for it.

I tried to test it properly, but please test it as well.

Here is what it looks like:

>>> Schema(os.path.isfile, error='File "{value}" does not exist').validate('/blah')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "schema.py", line 178, in validate
    data)
schema.SchemaError: File "/blah" does not exist

Or from what I put in the readme:

>>> Schema(Use(int, error='Invalid year: {value}')).validate('XVII')
Traceback (most recent call last):
...
SchemaError: Invalid year: XVII

More complex example:

>>> try:
...  Schema({1: Or(int, float, error='B> {value}')}, 'A> {value}').validate({1:'a'})
... except Exception as e:
...  print 'value:', e.value
...  print 'message:', e.message.encode('string-escape')
... 
value: {1: 'a'}
message: A> {1: \'a\'}\nB> a
>>>

Tell me what you think.

edit: maybe better comment on the PR: #17

@keleshev
Copy link
Owner

I think this is useful, but I'm not 100% about the {value} syntax. Let me think if there is any better alternative.

Rogdham added a commit to Rogdham/schema that referenced this issue May 14, 2013
Rogdham added a commit to Rogdham/schema that referenced this issue May 18, 2013
@c-holtermann
Copy link

I'd like that feature - it doesn't seem to be working, is it ?

@Rogdham
Copy link
Contributor

Rogdham commented Oct 24, 2013

Hi @c-holtermann, it is not working at the moment, but I've submitted a pull request here. Feel free to test it and share your thoughts there!

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

No branches or pull requests

4 participants