Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Remove the top level error if it indicates an empty name #9763

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion confmap/confmap.go
Expand Up @@ -5,8 +5,10 @@ package confmap // import "go.opentelemetry.io/collector/confmap"

import (
"encoding"
"errors"
"fmt"
"reflect"
"strings"

"github.com/go-viper/mapstructure/v2"
"github.com/knadh/koanf/maps"
Expand Down Expand Up @@ -167,7 +169,13 @@ func decodeConfig(m *Conf, result any, errorUnused bool) error {
if err != nil {
return err
}
return decoder.Decode(m.ToStringMap())
if err = decoder.Decode(m.ToStringMap()); err != nil {
if strings.HasPrefix(err.Error(), "error decoding ''") {
return errors.Unwrap(err)
}
return err
}
return nil
}

// encoderConfig returns a default encoder.EncoderConfig that includes
Expand Down
4 changes: 2 additions & 2 deletions confmap/confmap_test.go
Expand Up @@ -450,7 +450,7 @@ func TestEmbeddedUnmarshalerError(t *testing.T) {
})

tc := &testConfigWithEmbeddedError{}
assert.EqualError(t, cfgMap.Unmarshal(tc), "error decoding '': embedded error")
assert.EqualError(t, cfgMap.Unmarshal(tc), "embedded error")
}

func TestEmbeddedMarshalerError(t *testing.T) {
Expand All @@ -462,7 +462,7 @@ func TestEmbeddedMarshalerError(t *testing.T) {
})

tc := &testConfigWithMarshalError{}
assert.EqualError(t, cfgMap.Unmarshal(tc), "error decoding '': error running encode hook: marshaling error")
assert.EqualError(t, cfgMap.Unmarshal(tc), "error running encode hook: marshaling error")
}

func TestUnmarshalerKeepAlreadyInitialized(t *testing.T) {
Expand Down