mirror of
https://github.com/spf13/viper
synced 2025-05-07 20:57:18 +00:00
Avoid pointer type
This commit is contained in:
parent
701e7d9615
commit
6e36571d0c
3 changed files with 9 additions and 12 deletions
4
util.go
4
util.go
|
@ -27,12 +27,12 @@ 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 {
|
||||
func (pe ConfigParseError) Unwrap() error {
|
||||
return pe.err
|
||||
}
|
||||
|
||||
|
|
2
viper.go
2
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}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1485,17 +1485,14 @@ func TestWrongDirsSearchNotFoundForMerge(t *testing.T) {
|
|||
assert.Equal(t, `default`, v.GetString(`key`))
|
||||
}
|
||||
|
||||
func TestUnwrap(t *testing.T) {
|
||||
yamlInvalid := []byte(`hash: map
|
||||
- foo
|
||||
- bar
|
||||
`)
|
||||
var yamlInvalid = []byte(`hash: map
|
||||
- foo
|
||||
- bar
|
||||
`)
|
||||
|
||||
func TestUnwrapParseErrors(t *testing.T) {
|
||||
SetConfigType("yaml")
|
||||
err := ReadConfig(bytes.NewBuffer(yamlInvalid))
|
||||
|
||||
var cpe ConfigParseError
|
||||
if !errors.As(err, &cpe) {
|
||||
if !errors.As(ReadConfig(bytes.NewBuffer(yamlInvalid)), &ConfigParseError{}) {
|
||||
t.Fatalf("not a ConfigParseError")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue