ctxutil

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(ctx context.Context) error

Cause returns the error and cause from the context as a single error with a nice message. This is an ergonomic convenience. `ctx.Err()` predates causes, and doesn't report them. `context.Cause(ctx)` returns the cause, but its message doesn't state that it's a cause. This function will return either:

For a context with a cause, the returned error will wrap both the error and the cause, so you can use `errors.Is`, `errors.As`, and `errors.Unwrap`.

func EnrichWithCause

func EnrichWithCause(err error, ctx context.Context) error

EnrichWithCause takes an error which should be returned from a function that also takes a context, and the context itself. If the context was canceled or its deadline was exceeded *with a cause*, and the error returned was the `ctx.Err()` without including the cause, then this function will return a new error that wraps both. This is an ergonomic convenience to adapt functions which respond to `ctx.Done()` but don't include the cause in their returned error, likely because they were written before context causes were added.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL