Skip to content

Commit

Permalink
fix: rerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Jun 19, 2024
1 parent 2a46495 commit d48eb71
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ We are looking for contributions and examples for:
- zap
- zerolog
- go-sentry
- otel
- other?

Examples of formatters can be found in `ToMap()`, `Format()`, `Marshal()` and `LogValuer` methods of `oops.OopsError`.
Expand Down
15 changes: 9 additions & 6 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

var SourceFragmentsHidden = true
var DereferencePointers = true
var Local *time.Location = time.UTC

var _ error = (*OopsError)(nil)
Expand Down Expand Up @@ -126,12 +127,14 @@ func (o OopsError) Tags() []string {

// Context returns a k/v context of the error.
func (o OopsError) Context() map[string]any {
return lazyMapEvaluation(
mergeNestedErrorMap(
o,
func(e OopsError) map[string]any {
return e.context
},
return dereferencePointers(
lazyMapEvaluation(
mergeNestedErrorMap(
o,
func(e OopsError) map[string]any {
return e.context
},
),
),
)
}
Expand Down
18 changes: 18 additions & 0 deletions kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ import (
"github.com/samber/lo"
)

func dereferencePointers(data map[string]any) map[string]any {
if !DereferencePointers {
return data
}

for key, value := range data {
val := reflect.ValueOf(value)
if val.Kind() == reflect.Ptr {
// @TODO: might be a pointer to a pointer
data[key] = val.Elem().Interface()
}
}

return data

}

func lazyMapEvaluation(data map[string]any) map[string]any {
for key, value := range data {
switch v := value.(type) {
Expand All @@ -18,6 +35,7 @@ func lazyMapEvaluation(data map[string]any) map[string]any {

return data
}

func lazyValueEvaluation(value any) any {
v := reflect.ValueOf(value)
if !v.IsValid() || v.Kind() != reflect.Func {
Expand Down

0 comments on commit d48eb71

Please sign in to comment.