Documentation
¶
Index ¶
Examples ¶
Constants ¶
const ( KindIO = "IO" KindType = "Type" KindUnknown = "" KindValue = "Value" )
Variables ¶
var ( // IncludeStack is used to determine whether or not a stacktrace should be captured with // new errors. By default it is set to true. IncludeStack = true // InspectFull controls how [From] operates. By default, the full error stack will be inspected // via [errors.As]. If any [evs.Error] exists within the stack, that error is extracted and returned. // You can turn this behavior off, by setting InspectFull to false. This will then only check the // error itself (without calling unwrap). InspectFull = true )
var ( // GetFormatterFunc should return the formatter that gets used in each instantiation of an error. You can // supply your own implementation if you would like to change how errors are formatted. See the source // code for the [textFormatter] to see how it is implemented. GetFormatterFunc = TextFormatter )
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { Wraps error Stack Stack Details []string Kind Kind // contains filtered or unexported fields }
Error implements both the Error interface as well as Unwrap.
func (*Error) Format ¶
Format implements the fmt.Formatter interface.
type Formatter ¶
Formatter is almost the same as the fmt.Formatter but passes the Error in as well.
func TextFormatter ¶
func TextFormatter() Formatter
TextFormatter returns the Formatter that is used by default. You can use this to restore default behavior if you swapped in your own Formatter at some point.
type Frame ¶
Frame defines a single frame in a stack trace.
func CurrentFrame ¶
CurrentFrame gets the location information for the code point where this function was called from (or anywhere up or down the stack from there depending on the skip value given.)
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record is a builder type that is used to build up an Error. Once you have created the error the way you want it to exist, call Record.Err to return an error type.
func From ¶
From generates a new record from the given error. If the error is nil, the record will contain a nil internal Error. If the given error is not nil, it first checks to see if it already contains a Error. If it does, it directly sets the underlying Error to that error. Otherwise, it creates a new Error that wraps the given error. Use this method if you don't intend to "wrap" [Error]s but rather just have one single error that you can pass around.
Example ¶
package main import ( "errors" "log" "github.com/thenorthnate/evs" ) func main() { err := errors.New("something terrible happened!") newErr := evs.From(err).Err() if newErr == nil { log.Fatal("This should be an error!") } }
func New ¶
New creates a new Record with the given message and the Std error type.
Example ¶
package main import ( "log" "github.com/thenorthnate/evs" ) func main() { err := evs.New("something terrible happened!").Err() if err == nil { log.Fatal("This should be an error!") } }
func (*Record) DropStack ¶
DropStack allows you to remove the stacktrace for this specific error. You might use this if you generally want the full stacktrace for everything (thus [IncludeStack]==true), but you don't want this error to have it.
func (*Record) Fmt ¶
Fmt allows you to set the Formatter you'd like to use which dictates how the messages are printed out.
func (*Record) Msgf ¶
Msgf is the same as Record.Msg except that it takes a variadic set of arguments.
type Stack ¶
type Stack struct {
Frames []Frame
}
Stack contains a stack trace made up of individual frames.