Installation¶
Usage Examples¶
Basic Error Handling¶
Create and wrap errors with context:
import "github.com/hyp3rd/ewrap"
// ...
// Create a new error
err := ewrap.New("database connection failed")
// Wrap an existing error with context
if err != nil {
return ewrap.Wrap(err, "failed to process request")
}
Advanced Error Context¶
Add rich context and metadata to errors:
import "github.com/hyp3rd/ewrap"
// ...
err := ewrap.New("operation failed",
ewrap.WithContext(ctx, ewrap.ErrorTypeDatabase, ewrap.SeverityCritical),
ewrap.WithLogger(logger)).
WithMetadata("query", "SELECT * FROM users").
WithMetadata("retry_count", 3)
// Log the error with all context
err.Log()
Error Groups with Pooling¶
Use error groups efficiently in high-throughput scenarios: