diff --git a/error.go b/error.go index 47a99e5a..344c52dc 100644 --- a/error.go +++ b/error.go @@ -16,12 +16,14 @@ type Error struct { func (e *Error) Error() string { points := make([]string, len(e.Errors)) for i, err := range e.Errors { + // split by newlines and indent each line + err = strings.Replace(err, "\n", "\n ", -1) points[i] = fmt.Sprintf("* %s", err) } sort.Strings(points) return fmt.Sprintf( - "%d error(s) decoding:\n\n%s", + "%d error(s) decoding:\n%s", len(e.Errors), strings.Join(points, "\n")) } diff --git a/mapstructure.go b/mapstructure.go index 7581806a..ce49da83 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -1441,7 +1441,12 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e } sort.Strings(keys) - err := fmt.Errorf("'%s' has invalid keys: %s", name, strings.Join(keys, ", ")) + var err error + if name == "" { + err = fmt.Errorf("invalid keys: %s", strings.Join(keys, ", ")) + } else { + err = fmt.Errorf("'%s' has invalid keys: %s", name, strings.Join(keys, ", ")) + } errors = appendErrors(errors, err) }