Avoid pointer type

This commit is contained in:
andig 2023-05-29 17:44:40 +02:00
parent 701e7d9615
commit 6e36571d0c
3 changed files with 9 additions and 12 deletions

View file

@ -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
}

View file

@ -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}
}
}

View file

@ -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")
}
}