Documentation ¶
Index ¶
- Variables
- func Errorf(format string, vals ...interface{}) error
- func New(msg string) error
- func NewFromStatus(code int) error
- func NewStatusError(code int, msg string) error
- func NewStatusErrorf(code int, format string, a ...interface{}) error
- func Trace(e error, t *template.Template) ([]string, error)
- func WithStack(err error) error
- func WithStatus(code int, err error) error
- type Sentineldeprecated
- type StackTracer
- type StatusCoder
Constants ¶
This section is empty.
Variables ¶
var PanicFormat = template.Must(template.New("standardFormat").Parse("{{.Function}}\n\t{{.File}}:{{.Line}}"))
PanicFormat is a template resembling the output of a `panic` used to convert a *runtime.Frame to a string. Each entry is formatted as:
FUNCTION_NAME FILE_NAME:LINE_NUMBER
var StandardFormat = template.Must(template.New("standardFormat").Parse("{{.Function}} ({{.File}}:{{.Line}})"))
StandardFormat is a one-line template used to convert a *runtime.Frame to a string. Each entry is formatted as:
FUNCTION_NAME (FILE_NAME:LINE_NUMBER)
Functions ¶
func Errorf ¶
Errorf wraps the error returned by fmt.Errorf in a StackErr. If there is an existing StackTracer in the unwrap chain, its stack trace will be preserved.
func NewFromStatus ¶ added in v0.3.1
NewFromStatus creates a new StatusError with the given status code and the HTTP status text from the standard library.
func NewStatusError ¶ added in v0.3.0
NewStatusError returns an error that bundles an HTTP status code. The stack trace will be captured.
func NewStatusErrorf ¶ added in v0.3.0
NewStatusErrorf returns an error that bundles an HTTP status code, sharing fmt.Errorf semantics. The stack trace will be captured if not already present.
func Trace ¶
Trace returns the stack trace information as a slice of strings formatted using the provided Go template. The valid fields in the template are Function, File, and Line. See StandardFormat for an example.
func WithStack ¶
WithStack takes in an error and returns an error wrapped in a StackErr with the location where an error was first created or returned from third-party code. If there is already an error in the error chain that exposes a stacktrace via the StackTrace() method, WithStack returns the passed-in error. If a nil error is passed in, nil is returned.
func WithStatus ¶ added in v0.3.0
WithStatus bundles an error with an HTTP status code. The stack trace will be captured if not already present.
Types ¶
type Sentinel
deprecated
type Sentinel string
Sentinel is a way to turn a constant string into an error. It allows you to safely declare a package-level error so that it can't be accidentally modified to refer to a different value.
Deprecated: For package-scoped errors or other errors that should not have stack traces, use the standard library's errors.New.
type StackTracer ¶
StackTracer defines an interface that's met by an error that returns a stacktrace. This is intended to be used by errors that capture the stacktrace to the source of the error. Each invocation of StackTrace() must return a new instance of *runtime.Frames, so that this method can be invoked more than once (runtime.Frames uses internal iteration and has no way to reset the iterator).
type StatusCoder ¶ added in v0.3.0
type StatusCoder interface {
StatusCode() int
}
StatusCoder represents something that returns a status code.