File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,11 @@ func (pe ConfigParseError) Error() string {
3131 return fmt .Sprintf ("While parsing config: %s" , pe .err .Error ())
3232}
3333
34+ // Unwrap returns the wrapped error.
35+ func (pe ConfigParseError ) Unwrap () error {
36+ return pe .err
37+ }
38+
3439// toCaseInsensitiveValue checks if the value is a map;
3540// if so, create a copy and lower-case the keys recursively.
3641func toCaseInsensitiveValue (value interface {}) interface {} {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ package viper
88import (
99 "bytes"
1010 "encoding/json"
11+ "errors"
1112 "io"
1213 "io/ioutil"
1314 "os"
@@ -1573,6 +1574,18 @@ func TestWrongDirsSearchNotFoundForMerge(t *testing.T) {
15731574 assert .Equal (t , `default` , v .GetString (`key` ))
15741575}
15751576
1577+ var yamlInvalid = []byte (`hash: map
1578+ - foo
1579+ - bar
1580+ ` )
1581+
1582+ func TestUnwrapParseErrors (t * testing.T ) {
1583+ SetConfigType ("yaml" )
1584+ if ! errors .As (ReadConfig (bytes .NewBuffer (yamlInvalid )), & ConfigParseError {}) {
1585+ t .Fatalf ("not a ConfigParseError" )
1586+ }
1587+ }
1588+
15761589func TestSub (t * testing.T ) {
15771590 v := New ()
15781591 v .SetConfigType ("yaml" )
You can’t perform that action at this time.
0 commit comments