mirror of
https://github.com/spf13/viper
synced 2024-12-22 11:37:02 +00:00
Allow ConfigParseError to unwrap (#1433)
* Allow ConfigParseError to unwrap * wip * Avoid pointer type
This commit is contained in:
parent
53cdb5253a
commit
21a7fd828e
2 changed files with 18 additions and 0 deletions
5
util.go
5
util.go
|
@ -31,6 +31,11 @@ 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{} {
|
||||
|
|
|
@ -8,6 +8,7 @@ package viper
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -1573,6 +1574,18 @@ func TestWrongDirsSearchNotFoundForMerge(t *testing.T) {
|
|||
assert.Equal(t, `default`, v.GetString(`key`))
|
||||
}
|
||||
|
||||
var yamlInvalid = []byte(`hash: map
|
||||
- foo
|
||||
- bar
|
||||
`)
|
||||
|
||||
func TestUnwrapParseErrors(t *testing.T) {
|
||||
SetConfigType("yaml")
|
||||
if !errors.As(ReadConfig(bytes.NewBuffer(yamlInvalid)), &ConfigParseError{}) {
|
||||
t.Fatalf("not a ConfigParseError")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSub(t *testing.T) {
|
||||
v := New()
|
||||
v.SetConfigType("yaml")
|
||||
|
|
Loading…
Reference in a new issue