MokoJs / moko

Generator powered models
51 stars 3 forks source link

Attach errors to validation error #2

Closed paglias closed 10 years ago

paglias commented 10 years ago

It would be useful to have the errors attached to the validation error when it occurs https://github.com/MokoJs/moko/blob/master/lib/prototype.js#L150

Also setting error.name to something meaningful like ValidationError would make it easier to recognize Moko generated errors

Great library, thanks :)

rschmukler commented 10 years ago

@paglias this sounds useful. For the error do you envision error.validationErrors? I'll implement later today.

paglias commented 10 years ago

@rschmukler the property name is the same for me, storing only validation erros, even error.errors would be fine. To make it more recognizable setting error.name to something meaningful would be fantastic

rschmukler commented 10 years ago

For error.name, what's the advantage compared to err.message which is already "validation failed""

paglias commented 10 years ago

Well, using a fixed message it's more or less the same. I've suggested using name because maybe you'll decide to change the message or make it more dynamic (like Validation failed for attrs [attr1, attr2] or whatever) while the name is more likely to stay as it is.

rschmukler commented 10 years ago

I think for now the name might be unnecessary. This is based off of my experience with modella. If people do end up requesting dynamic errors I will add a more static name property. The issue is if we add name here, we should also add it to things like sync errors.

I do agree with having error.errors be made available.