Allow ConfigParseError to unwrap

This commit is contained in:
andig 2022-09-18 13:50:47 +02:00
parent 419fd86e49
commit d4014cfce7
2 changed files with 7 additions and 2 deletions

View file

@ -27,10 +27,15 @@ type ConfigParseError struct {
}
// Error returns the formatted configuration error.
func (pe ConfigParseError) Error() string {
func (pe *ConfigParseError) Error() string {
return fmt.Sprintf("While parsing config: %s", pe.err.Error())
}
// Unwrap returns the wrapped error.
func (pe *ConfigParseError) Unwrap() error {
return pe.err
}
// toCaseInsensitiveValue checks if the value is a map;
// if so, create a copy and lower-case the keys recursively.
func toCaseInsensitiveValue(value interface{}) interface{} {

View file

@ -1700,7 +1700,7 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
case "yaml", "yml", "json", "toml", "hcl", "tfvars", "ini", "properties", "props", "prop", "dotenv", "env":
err := v.decoderRegistry.Decode(format, buf.Bytes(), c)
if err != nil {
return ConfigParseError{err}
return &ConfigParseError{err}
}
}