Documentation
¶
Overview ¶
Package errors extends the standard library errors package with additional APIs to: - wrap errors with additional tags - read attached tags from errors
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( New = errors.New Is = errors.Is As = errors.As Unwrap = errors.Unwrap Join = errors.Join )
Aliases to the standard error types
Functions ¶
func Wrap ¶
Wrap attaches additional tags to an error.
Example ¶
package main
import (
"fmt"
"github.com/gojekfarm/xtools/errors"
)
func main() {
// Create a generic error
err := errors.New("record not found")
// Wrap the error with key-value pairs
wrapped := errors.Wrap(
err,
"table", "users",
"id", "123",
)
// Add more tags as the error propagates
wrapped = errors.Wrap(
wrapped,
"experiment_id", "456",
)
// errors.Is will check for not found error
fmt.Println(errors.Is(wrapped, err))
// Use errors.As to read attached tags.
var errTags *errors.ErrorTags
errors.As(wrapped, &errTags)
// Use the tags to construct detailed error messages,
// log additional context, or return structured errors.
fmt.Println(errTags.All())
}
Types ¶
type ErrorTags ¶
type ErrorTags struct {
// contains filtered or unexported fields
}
ErrorTags is an error that has key-value tags attached to it.
Click to show internal directories.
Click to hide internal directories.