alecthomas/voluptuous — pull request #81 by bdejong (2014-08-07 07:28:30+00:00)
Title: Added specific errors for most validation errors

Hi Alec,

This is the start of the spefic-errors-per-validation-error-type. Could you possibly review this before I start adding more things?

There are a few doubts for the Marker and Msg objects as there I'm not sure what error path leads to these... I marked the lines:

```python
class Marker(object):
def __init__(self, schema, msg=None):
self.schema = schema
self._schema = Schema(schema)
self.msg = msg

def __call__(self, v):
try:
return self._schema(v)
except Invalid as e:
if not self.msg or len(e.path) > 1:
raise
raise Invalid(self.msg) # <------------------------------- ?

def __str__(self):
return str(self.schema)

def __repr__(self):
return repr(self.schema)

def Msg(schema, msg):
schema = Schema(schema)

@wraps(Msg)
def f(v):
try:
return schema(v)
except Invalid as e:
if len(e.path) > 1:
raise e
else:
raise Invalid(msg) # <---------------------------------- ?
return f
```