Skip to content

Commit

Permalink
Just forgot WrapError after all the refactorings, urgh
Browse files Browse the repository at this point in the history
  • Loading branch information
theHamdiz committed Feb 2, 2025
1 parent 70d80bd commit ccffd4c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions it.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ func Should[T any](operation func() (T, error)) T {
return result
}

// WrapError wraps an error with a custom message and additional metadata.
// If the original error is nil, it simply returns nil.
func WrapError(err error, message string, metadata map[string]any) error {
if err == nil {
return nil
}

wrappedMessage := fmt.Sprintf("%s: %v", message, err)
if metadata != nil && len(metadata) > 0 {
wrappedMessage += fmt.Sprintf(" | Metadata: %+v", metadata)
}

return errors.New(wrappedMessage)
}

// ===================================================
// Goroutine Management - Threading The Needle
// ===================================================
Expand Down

0 comments on commit ccffd4c

Please sign in to comment.