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

Bug: types.WithMetadatas fails because of assignment to nil map #193

Open
mempirate opened this issue Jan 26, 2025 · 1 comment
Open

Bug: types.WithMetadatas fails because of assignment to nil map #193

mempirate opened this issue Jan 26, 2025 · 1 comment

Comments

@mempirate
Copy link

The WithMetadatas(md) record option fails, because it is trying to set a value on an uninitialized map:

func WithMetadatas(metadata map[string]interface{}) Option {
return func(r *Record) error {
for k, v := range metadata {
switch v.(type) {
case string, int, float32, bool:
r.Metadata[k] = v
default:
return &InvalidMetadataValueError{Key: k, Value: v}
}
}
return nil
}
}

The map should be initialized like in WithMetadata:

func WithMetadata(key string, value interface{}) Option {
return func(r *Record) error {
if r.Metadata == nil {
r.Metadata = map[string]interface{}{}
}
switch value.(type) {
case string, int, float32, bool:
r.Metadata[key] = value
default:
return &InvalidMetadataValueError{Key: key, Value: value}
}
return nil
}
}

@mempirate mempirate changed the title Bug: record.WithMetadatas fails because of assignment to nil map Bug: types.WithMetadatas fails because of assignment to nil map Jan 26, 2025
@tazarov
Copy link
Contributor

tazarov commented Jan 29, 2025

@mempirate, I'll fix shortly in #189. Thanks for raising this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants