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] cleanup tostring function, remove unclear uri parameter #10244

Merged
merged 1 commit into from
May 28, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {})`)
}
Loading