mirror of
https://github.com/spf13/viper
synced 2024-11-16 18:07:02 +00:00
Allow ConfigParseError to unwrap (#1433)
* Allow ConfigParseError to unwrap * wip * Avoid pointer type
This commit is contained in:
parent
53cdb5253a
commit
c19a006378
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())
|
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;
|
// toCaseInsensitiveValue checks if the value is a map;
|
||||||
// if so, create a copy and lower-case the keys recursively.
|
// if so, create a copy and lower-case the keys recursively.
|
||||||
func toCaseInsensitiveValue(value interface{}) interface{} {
|
func toCaseInsensitiveValue(value interface{}) interface{} {
|
||||||
|
|
|
@ -8,6 +8,7 @@ package viper
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -1573,6 +1574,18 @@ func TestWrongDirsSearchNotFoundForMerge(t *testing.T) {
|
||||||
assert.Equal(t, `default`, v.GetString(`key`))
|
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) {
|
func TestSub(t *testing.T) {
|
||||||
v := New()
|
v := New()
|
||||||
v.SetConfigType("yaml")
|
v.SetConfigType("yaml")
|
||||||
|
|
Loading…
Reference in a new issue