Skip to content
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
12 changes: 10 additions & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,12 @@ func (o OopsError) ToMap() map[string]any { //nolint:gocyclo

if s.userID != "" || len(s.userData) > 0 {
// snapshot() owns s.userData (freshly merged in mergeMaps), so it can
// be used directly instead of copying.
// be used directly instead of copying. It is nil when only the user
// ID was set.
user := s.userData
if user == nil {
user = map[string]any{}
}
if s.userID != "" {
user["id"] = s.userID
}
Expand All @@ -754,8 +758,12 @@ func (o OopsError) ToMap() map[string]any { //nolint:gocyclo

if s.tenantID != "" || len(s.tenantData) > 0 {
// snapshot() owns s.tenantData (freshly merged in mergeMaps), so it can
// be used directly instead of copying.
// be used directly instead of copying. It is nil when only the tenant
// ID was set.
tenant := s.tenantData
if tenant == nil {
tenant = map[string]any{}
}
if s.tenantID != "" {
tenant["id"] = s.tenantID
}
Expand Down
14 changes: 11 additions & 3 deletions kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,17 @@ func snapshot(o OopsError) OopsError { //nolint:gocyclo
}

s.tags = lo.Uniq(s.tags)
s.context = dereferencePointers(lazyMapEvaluation(mergeMaps(contextMaps)))
s.userData = dereferencePointers(lazyMapEvaluation(mergeMaps(userDataMaps)))
s.tenantData = dereferencePointers(lazyMapEvaluation(mergeMaps(tenantDataMaps)))
// Only merge when the chain actually carries maps: mergeMaps allocates
// even for empty input, and consumers only ever check len() on these.
if len(contextMaps) > 0 {
s.context = dereferencePointers(lazyMapEvaluation(mergeMaps(contextMaps)))
}
if len(userDataMaps) > 0 {
s.userData = dereferencePointers(lazyMapEvaluation(mergeMaps(userDataMaps)))
}
if len(tenantDataMaps) > 0 {
s.tenantData = dereferencePointers(lazyMapEvaluation(mergeMaps(tenantDataMaps)))
}

return s
}
Expand Down
Loading