Documentation ¶
Index ¶
- Variables
- func Errorf(format string, args ...any) error
- func GetPublic(err error, defaultPublicMessage string) string
- func Join(e ...error) error
- func Recover(cb func()) (err error)
- func Recoverf(cb func(), msg string, args ...any) (err error)
- func WithBuilder(ctx context.Context, builder OopsErrorBuilder) context.Context
- func Wrap(err error) error
- func Wrap10[A any, B any, C any, D any, E any, F any, G any, H any, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I, err error) (A, B, C, D, E, F, G, H, I, error)
- func Wrap2[A any](a A, err error) (A, error)
- func Wrap3[A any, B any](a A, b B, err error) (A, B, error)
- func Wrap4[A any, B any, C any](a A, b B, c C, err error) (A, B, C, error)
- func Wrap5[A any, B any, C any, D any](a A, b B, c C, d D, err error) (A, B, C, D, error)
- func Wrap6[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E, err error) (A, B, C, D, E, error)
- func Wrap7[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F, err error) (A, B, C, D, E, F, error)
- func Wrap8[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G, err error) (A, B, C, D, E, F, G, error)
- func Wrap9[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H, err error) (A, B, C, D, E, F, G, H, error)
- func Wrapf(err error, format string, args ...any) error
- func Wrapf10[A any, B any, C any, D any, E any, F any, G any, H any, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I, err error, format string, ...) (A, B, C, D, E, F, G, H, I, error)
- func Wrapf2[A any](a A, err error, format string, args ...any) (A, error)
- func Wrapf3[A any, B any](a A, b B, err error, format string, args ...any) (A, B, error)
- func Wrapf4[A any, B any, C any](a A, b B, c C, err error, format string, args ...any) (A, B, C, error)
- func Wrapf5[A any, B any, C any, D any](a A, b B, c C, d D, err error, format string, args ...any) (A, B, C, D, error)
- func Wrapf6[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E, err error, format string, args ...any) (A, B, C, D, E, error)
- func Wrapf7[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F, err error, format string, args ...any) (A, B, C, D, E, F, error)
- func Wrapf8[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G, err error, format string, args ...any) (A, B, C, D, E, F, G, error)
- func Wrapf9[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H, err error, format string, args ...any) (A, B, C, D, E, F, G, H, error)
- type OopsError
- func (o OopsError) Code() string
- func (o OopsError) Context() map[string]any
- func (o OopsError) Domain() string
- func (o OopsError) Duration() time.Duration
- func (o OopsError) Error() string
- func (o OopsError) Format(s fmt.State, verb rune)
- func (o OopsError) Hint() string
- func (c OopsError) Is(err error) bool
- func (o OopsError) LogValuer() slog.Value
- func (o OopsError) MarshalJSON() ([]byte, error)
- func (o OopsError) Owner() string
- func (o OopsError) Public() string
- func (o OopsError) Request() *http.Request
- func (o OopsError) Response() *http.Response
- func (o OopsError) Sources() string
- func (o OopsError) Span() string
- func (o OopsError) Stacktrace() string
- func (o OopsError) Tags() []string
- func (o OopsError) Tenant() (string, map[string]any)
- func (o OopsError) Time() time.Time
- func (o OopsError) ToMap() map[string]any
- func (o OopsError) Trace() string
- func (o OopsError) Unwrap() error
- func (o OopsError) User() (string, map[string]any)
- type OopsErrorBuilder
- func Assert(condition bool) OopsErrorBuilder
- func Assertf(condition bool, msg string, args ...any) OopsErrorBuilder
- func Code(code string) OopsErrorBuilder
- func Duration(duration time.Duration) OopsErrorBuilder
- func FromContext(ctx context.Context) OopsErrorBuilder
- func Hint(hint string) OopsErrorBuilder
- func In(domain string) OopsErrorBuilder
- func Owner(owner string) OopsErrorBuilder
- func Public(public string) OopsErrorBuilder
- func Request(req *http.Request, withBody bool) OopsErrorBuilder
- func Response(res *http.Response, withBody bool) OopsErrorBuilder
- func Since(time time.Time) OopsErrorBuilder
- func Span(span string) OopsErrorBuilder
- func Tags(tags ...string) OopsErrorBuilder
- func Tenant(tenantID string, data map[string]any) OopsErrorBuilder
- func Time(time time.Time) OopsErrorBuilder
- func Trace(trace string) OopsErrorBuilder
- func User(userID string, data map[string]any) OopsErrorBuilder
- func With(kv ...any) OopsErrorBuilder
- func WithContext(ctx context.Context, keys ...any) OopsErrorBuilder
- func (o OopsErrorBuilder) Assert(condition bool) OopsErrorBuilder
- func (o OopsErrorBuilder) Assertf(condition bool, msg string, args ...any) OopsErrorBuilder
- func (o OopsErrorBuilder) Code(code string) OopsErrorBuilder
- func (o OopsErrorBuilder) Duration(duration time.Duration) OopsErrorBuilder
- func (o OopsErrorBuilder) Errorf(format string, args ...any) error
- func (o OopsErrorBuilder) Hint(hint string) OopsErrorBuilder
- func (o OopsErrorBuilder) In(domain string) OopsErrorBuilder
- func (o OopsErrorBuilder) Join(e ...error) error
- func (o OopsErrorBuilder) Owner(owner string) OopsErrorBuilder
- func (o OopsErrorBuilder) Public(public string) OopsErrorBuilder
- func (o OopsErrorBuilder) Recover(cb func()) (err error)
- func (o OopsErrorBuilder) Recoverf(cb func(), msg string, args ...any) (err error)
- func (o OopsErrorBuilder) Request(req *http.Request, withBody bool) OopsErrorBuilder
- func (o OopsErrorBuilder) Response(res *http.Response, withBody bool) OopsErrorBuilder
- func (o OopsErrorBuilder) Since(t time.Time) OopsErrorBuilder
- func (o OopsErrorBuilder) Span(span string) OopsErrorBuilder
- func (o OopsErrorBuilder) Tags(tags ...string) OopsErrorBuilder
- func (o OopsErrorBuilder) Tenant(tenantID string, tenantData ...any) OopsErrorBuilder
- func (o OopsErrorBuilder) Time(time time.Time) OopsErrorBuilder
- func (o OopsErrorBuilder) Trace(trace string) OopsErrorBuilder
- func (o OopsErrorBuilder) User(userID string, userData ...any) OopsErrorBuilder
- func (o OopsErrorBuilder) With(kv ...any) OopsErrorBuilder
- func (o OopsErrorBuilder) WithContext(ctx context.Context, keys ...any) OopsErrorBuilder
- func (o OopsErrorBuilder) Wrap(err error) error
- func (o OopsErrorBuilder) Wrapf(err error, format string, args ...any) error
Constants ¶
This section is empty.
Variables ¶
var ( SourceFragmentsHidden = true DereferencePointers = true Local *time.Location = time.UTC )
var (
StackTraceMaxDepth int = 10
)
Functions ¶
func GetPublic ¶ added in v1.13.0
GetPublic returns a message that is safe to show to an end user, or a default generic message.
func Recover ¶
func Recover(cb func()) (err error)
Recover handle panic and returns `oops.OopsError` object that satisfies `error`.
func Recoverf ¶
Recoverf handle panic and returns `oops.OopsError` object that satisfies `error` and formats an error message.
func WithBuilder ¶ added in v1.15.0
func WithBuilder(ctx context.Context, builder OopsErrorBuilder) context.Context
WithBuilder set the error builder in the context, to be retrieved later with FromContext.
func Wrapf ¶
Wrapf wraps an error into an `oops.OopsError` object that satisfies `error` and formats an error message.
Types ¶
type OopsError ¶
type OopsError struct {
// contains filtered or unexported fields
}
func (OopsError) Code ¶
Code returns the error cause. Error code is intented to be used by machines.
func (OopsError) Format ¶
Format implements fmt.Formatter. If the format is "%+v", then the details of the error are included. Otherwise, using "%v", just the summary is included.
func (OopsError) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (OopsError) Public ¶ added in v1.13.0
Public returns a message that is safe to show to an end user.
func (OopsError) Stacktrace ¶
Stacktrace returns a pretty printed stacktrace of the error.
type OopsErrorBuilder ¶
type OopsErrorBuilder OopsError
*
- Builder pattern. *
- oops.Errorf("Could not fetch users: %w", err) *
- oops.
- User("[email protected]", "firstname", "Samuel").
- Tenant("apple", "country", "us").
- Errorf("403 not permitted") *
- oops.
- Time(requestDate).
- Duration(requestDuration).
- Tx(traceID).
- Errorf("Failed to execute http request") *
- oops.
- With("project_id", project.ID, "created_at", project.CreatedAt).
- Errorf("Could not update settings") *
func Assert ¶ added in v1.1.0
func Assert(condition bool) OopsErrorBuilder
Assert panics if condition is false. Panic payload will be of type oops.OopsError. Assertions can be chained.
func Assertf ¶ added in v1.1.0
func Assertf(condition bool, msg string, args ...any) OopsErrorBuilder
Assertf panics if condition is false. Panic payload will be of type oops.OopsError. Assertions can be chained.
func Code ¶
func Code(code string) OopsErrorBuilder
Code set a code or slug that describes the error. Error messages are intented to be read by humans, but such code is expected to be read by machines and even transported over different services.
func Duration ¶
func Duration(duration time.Duration) OopsErrorBuilder
Duration set the error duration.
func FromContext ¶ added in v1.15.0
func FromContext(ctx context.Context) OopsErrorBuilder
func Owner ¶
func Owner(owner string) OopsErrorBuilder
Owner set the name/email of the collegue/team responsible for handling this error. Useful for alerting purpose.
func Public ¶ added in v1.13.1
func Public(public string) OopsErrorBuilder
Public sets a message that is safe to show to an end user.
func Request ¶ added in v1.3.0
func Request(req *http.Request, withBody bool) OopsErrorBuilder
Request supplies a http.Request.
func Response ¶ added in v1.3.0
func Response(res *http.Response, withBody bool) OopsErrorBuilder
Response supplies a http.Response.
func Tags ¶
func Tags(tags ...string) OopsErrorBuilder
Tags adds multiple tags, describing the feature returning an error.
func Tenant ¶
func Tenant(tenantID string, data map[string]any) OopsErrorBuilder
Tenant supplies tenant id and a chain of key/value.
func Time ¶
func Time(time time.Time) OopsErrorBuilder
Time set the error time. Default: `time.Now()`
func Trace ¶
func Trace(trace string) OopsErrorBuilder
Trace set a transaction id, trace id or correlation id...
func User ¶
func User(userID string, data map[string]any) OopsErrorBuilder
User supplies user id and a chain of key/value.
func With ¶
func With(kv ...any) OopsErrorBuilder
With supplies a list of attributes declared by pair of key+value.
func WithContext ¶ added in v1.8.0
func WithContext(ctx context.Context, keys ...any) OopsErrorBuilder
With supplies a list of attributes declared by pair of key+value.
func (OopsErrorBuilder) Assert ¶ added in v1.1.0
func (o OopsErrorBuilder) Assert(condition bool) OopsErrorBuilder
Assert panics if condition is false. Panic payload will be of type oops.OopsError. Assertions can be chained.
func (OopsErrorBuilder) Assertf ¶ added in v1.1.0
func (o OopsErrorBuilder) Assertf(condition bool, msg string, args ...any) OopsErrorBuilder
Assertf panics if condition is false. Panic payload will be of type oops.OopsError. Assertions can be chained.
func (OopsErrorBuilder) Code ¶
func (o OopsErrorBuilder) Code(code string) OopsErrorBuilder
Code set a code or slug that describes the error. Error messages are intented to be read by humans, but such code is expected to be read by machines and even transported over different services.
func (OopsErrorBuilder) Duration ¶
func (o OopsErrorBuilder) Duration(duration time.Duration) OopsErrorBuilder
Duration set the error duration.
func (OopsErrorBuilder) Errorf ¶
func (o OopsErrorBuilder) Errorf(format string, args ...any) error
Errorf formats an error and returns `oops.OopsError` object that satisfies `error`.
func (OopsErrorBuilder) Hint ¶
func (o OopsErrorBuilder) Hint(hint string) OopsErrorBuilder
Hint set a hint for faster debugging.
func (OopsErrorBuilder) In ¶
func (o OopsErrorBuilder) In(domain string) OopsErrorBuilder
In set the feature category or domain.
func (OopsErrorBuilder) Join ¶ added in v1.12.0
func (o OopsErrorBuilder) Join(e ...error) error
func (OopsErrorBuilder) Owner ¶
func (o OopsErrorBuilder) Owner(owner string) OopsErrorBuilder
Owner set the name/email of the collegue/team responsible for handling this error. Useful for alerting purpose.
func (OopsErrorBuilder) Public ¶ added in v1.13.0
func (o OopsErrorBuilder) Public(public string) OopsErrorBuilder
Public represents a message that is safe to be shown to an end-user.
func (OopsErrorBuilder) Recover ¶
func (o OopsErrorBuilder) Recover(cb func()) (err error)
Recover handle panic and returns `oops.OopsError` object that satisfies `error`.
func (OopsErrorBuilder) Recoverf ¶
func (o OopsErrorBuilder) Recoverf(cb func(), msg string, args ...any) (err error)
Recoverf handle panic and returns `oops.OopsError` object that satisfies `error` and formats an error message.
func (OopsErrorBuilder) Request ¶ added in v1.3.0
func (o OopsErrorBuilder) Request(req *http.Request, withBody bool) OopsErrorBuilder
Request supplies a http.Request.
func (OopsErrorBuilder) Response ¶ added in v1.3.0
func (o OopsErrorBuilder) Response(res *http.Response, withBody bool) OopsErrorBuilder
Response supplies a http.Response.
func (OopsErrorBuilder) Since ¶
func (o OopsErrorBuilder) Since(t time.Time) OopsErrorBuilder
Since set the error duration.
func (OopsErrorBuilder) Span ¶
func (o OopsErrorBuilder) Span(span string) OopsErrorBuilder
Span represents a unit of work or operation.
func (OopsErrorBuilder) Tags ¶
func (o OopsErrorBuilder) Tags(tags ...string) OopsErrorBuilder
Tags adds multiple tags, describing the feature returning an error.
func (OopsErrorBuilder) Tenant ¶
func (o OopsErrorBuilder) Tenant(tenantID string, tenantData ...any) OopsErrorBuilder
Tenant supplies tenant id and a chain of key/value.
func (OopsErrorBuilder) Time ¶
func (o OopsErrorBuilder) Time(time time.Time) OopsErrorBuilder
Time set the error time. Default: `time.Now()`
func (OopsErrorBuilder) Trace ¶
func (o OopsErrorBuilder) Trace(trace string) OopsErrorBuilder
Trace set a transaction id, trace id or correlation id...
func (OopsErrorBuilder) User ¶
func (o OopsErrorBuilder) User(userID string, userData ...any) OopsErrorBuilder
User supplies user id and a chain of key/value.
func (OopsErrorBuilder) With ¶
func (o OopsErrorBuilder) With(kv ...any) OopsErrorBuilder
With supplies a list of attributes declared by pair of key+value.
func (OopsErrorBuilder) WithContext ¶ added in v1.8.0
func (o OopsErrorBuilder) WithContext(ctx context.Context, keys ...any) OopsErrorBuilder
WithContext supplies a list of values declared in context.
func (OopsErrorBuilder) Wrap ¶
func (o OopsErrorBuilder) Wrap(err error) error
Wrap wraps an error into an `oops.OopsError` object that satisfies `error`