errors

package module
v0.0.0-...-57ad34d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: ISC Imports: 1 Imported by: 0

README

errors

-- import "vimagination.zapto.org/errors"

Package errors is a simple package with a few error related types.

Usage

func AddTrace
func AddTrace(e error) error

AddTrace wraps an error with a call stack.

func New
func New(str string) error

New returns an error that returns the given string.

func Unwrap
func Unwrap(err error) error

Unwrap repeatedly checks for an underlying error to returned the original wrapped error.

func WithContext
func WithContext(context string, err error) error

WithContext wraps an error, adding textural context to the error message.

The wrapped error can be accessed via the Unwrap method.

A nil error will not be wrapped.

type Call
type Call struct {
	File, Function string
	LineNum        int
}

Call represents where a particular error was created.

func (Call) String
func (c Call) String() string

String returns a human-friendly representation of the call site.

type Error
type Error string

Error represents a constant error string.

func (Error) Error
func (e Error) Error() string

Error returns the error string.

type Trace
type Trace struct {
	Traces []Call
}

Trace represents the call stack for an error.

func (Trace) Trace
func (t Trace) Trace() []byte

Trace returns a byte slice containing a description of the call stack.

func (Trace) Unwrap
func (t Trace) Unwrap() error

Unwrap returns the underlying error.

type Wrapper
type Wrapper interface {
	Unwrap() error
}

Wrapper is used to get the underlying error for a wrapped error.

Documentation

Overview

Package errors is a simple package with a few error related types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTrace

func AddTrace(e error) error

AddTrace wraps an error with a call stack.

func New

func New(str string) error

New returns an error that returns the given string.

func Unwrap

func Unwrap(err error) error

Unwrap repeatedly checks for an underlying error to returned the original wrapped error.

func WithContext

func WithContext(context string, err error) error

WithContext wraps an error, adding textural context to the error message.

The wrapped error can be accessed via the Unwrap method.

A nil error will not be wrapped.

Types

type Call

type Call struct {
	File, Function string
	LineNum        int
}

Call represents where a particular error was created.

func (Call) String

func (c Call) String() string

String returns a human-friendly representation of the call site.

type Error

type Error string

Error represents a constant error string.

func (Error) Error

func (e Error) Error() string

Error returns the error string.

type Trace

type Trace struct {
	Traces []Call
	// contains filtered or unexported fields
}

Trace represents the call stack for an error.

func (Trace) Trace

func (t Trace) Trace() []byte

Trace returns a byte slice containing a description of the call stack.

func (Trace) Unwrap

func (t Trace) Unwrap() error

Unwrap returns the underlying error.

type Wrapper

type Wrapper interface {
	Unwrap() error
}

Wrapper is used to get the underlying error for a wrapped error.

Jump to

Keyboard shortcuts

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