From d4014cfce75f78209a46cec221d0672491c0bf1f Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 18 Sep 2022 13:50:47 +0200 Subject: [PATCH] Allow ConfigParseError to unwrap --- util.go | 7 ++++++- viper.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/util.go b/util.go index 64e6575..3217052 100644 --- a/util.go +++ b/util.go @@ -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{} { diff --git a/viper.go b/viper.go index 5f76cc0..11f50ba 100644 --- a/viper.go +++ b/viper.go @@ -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} } }