Validate enums (finally).

This commit is contained in:
Alec Thomas
2018-09-23 19:59:25 +10:00
parent d648254c7d
commit 5d7703774f
3 changed files with 24 additions and 0 deletions
+5
View File
@@ -269,6 +269,11 @@ func (v *Value) IsBool() bool {
// Parse tokens into value, parse, and validate, but do not write to the field.
func (v *Value) Parse(scan *Scanner, target reflect.Value) error {
defer func() {
if err := recover(); err != nil {
panic(fmt.Sprintf("mapper %T failed to apply to %s: %s", v.Mapper, v.Summary(), err))
}
}()
err := v.Mapper.Decode(&DecodeContext{Value: v, Scan: scan}, target)
if err != nil {
return fmt.Errorf("%s: %s", v.Summary(), err)