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. // 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()) return fmt.Sprintf("While parsing config: %s", pe.err.Error())
} }
// Unwrap returns the wrapped error. // Unwrap returns the wrapped error.
func (pe *ConfigParseError) Unwrap() error { func (pe ConfigParseError) Unwrap() error {
return pe.err 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": case "yaml", "yml", "json", "toml", "hcl", "tfvars", "ini", "properties", "props", "prop", "dotenv", "env":
err := v.decoderRegistry.Decode(format, buf.Bytes(), c) err := v.decoderRegistry.Decode(format, buf.Bytes(), c)
if err != nil { 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`)) assert.Equal(t, `default`, v.GetString(`key`))
} }
func TestUnwrap(t *testing.T) { var yamlInvalid = []byte(`hash: map
yamlInvalid := []byte(`hash: map - foo
- foo - bar
- bar `)
`)
func TestUnwrapParseErrors(t *testing.T) {
SetConfigType("yaml") SetConfigType("yaml")
err := ReadConfig(bytes.NewBuffer(yamlInvalid)) if !errors.As(ReadConfig(bytes.NewBuffer(yamlInvalid)), &ConfigParseError{}) {
var cpe ConfigParseError
if !errors.As(err, &cpe) {
t.Fatalf("not a ConfigParseError") t.Fatalf("not a ConfigParseError")
} }
} }