Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cause ¶
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:
- nil, if the context is not done
- the error from `ctx.Err()` if there is no separate cause, which will be either context.Canceled or context.DeadlineExceeded
- an error stating that the context.Canceled or context.DeadlineExceeded was caused by the cause, if there is a cause
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 ¶
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.