Skip to content

Commit

Permalink
[chore] cleanup tostring function, remove unclear uri parameter (open…
Browse files Browse the repository at this point in the history
…-telemetry#10244)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored and steves-canva committed Jun 13, 2024
1 parent 50fd50a commit 9618533
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions confmap/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func (mr *Resolver) findAndExpandURI(ctx context.Context, input string) (any, bo
if err != nil {
return input, false, err
}
repl, err := toString(uri, expanded)
repl, err := toString(expanded)
if err != nil {
return input, false, err
return input, false, fmt.Errorf("expanding %v: %w", uri, err)
}
return strings.ReplaceAll(input, uri, repl), changed, err
}

// toString attempts to convert input to a string.
func toString(strURI string, input any) (string, error) {
func toString(input any) (string, error) {
// This list must be kept in sync with checkRawConfType.
val := reflect.ValueOf(input)
switch val.Kind() {
Expand All @@ -134,7 +134,7 @@ func toString(strURI string, input any) (string, error) {
case reflect.Bool:
return strconv.FormatBool(val.Bool()), nil
default:
return "", fmt.Errorf("expanding %v, expected convertable to string value type, got %q(%T)", strURI, input, input)
return "", fmt.Errorf("expected convertable to string value type, got %q(%T)", input, input)
}
}

Expand Down
2 changes: 1 addition & 1 deletion confmap/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,5 @@ func TestResolverExpandStringValueInvalidReturnValue(t *testing.T) {
require.NoError(t, err)

_, err = resolver.Resolve(context.Background())
assert.EqualError(t, err, `expanding ${test:PORT}, expected convertable to string value type, got ['ӛ']([]interface {})`)
assert.EqualError(t, err, `expanding ${test:PORT}: expected convertable to string value type, got ['ӛ']([]interface {})`)
}

0 comments on commit 9618533

Please sign in to comment.