Documentation ยถ
Index ยถ
- Variables
- func RegisterErrorSeverity(severity ErrorSeverity) error
- func ResetState()
- func UnregisterErrorSeverity(severity ErrorSeverity)
- type Caller
- type Configuration
- func (c *Configuration) CaptureCaller() bool
- func (c *Configuration) CaptureProcess() bool
- func (c *Configuration) CaptureSourceFragments() bool
- func (c *Configuration) IgnoreBreakpoints() bool
- func (c *Configuration) MarshalMinimalJSON() bool
- func (c *Configuration) NextErrorIndex() int
- func (c *Configuration) Set(captureCaller bool, captureProcess bool, captureSourceFragments bool, ...)
- func (c *Configuration) SetCaptureCaller(capture bool)
- func (c *Configuration) SetCaptureProcess(capture bool)
- func (c *Configuration) SetCaptureSourceFragments(capture bool)
- func (c *Configuration) SetIgnoreBreakpoints(ignore bool)
- func (c *Configuration) SetMarshalMinimalJSON(minimal bool)
- func (c *Configuration) SetNextErrorIndex(index int)
- func (c *Configuration) SetSourceFragmentRadius(radius int)
- func (c *Configuration) SetTrackSimilarErrors(track bool)
- func (c *Configuration) SourceFragmentRadius() int
- func (c *Configuration) TrackSimilarErrors() bool
- type Error
- func (e Error) As(target interface{}) bool
- func (e Error) Chain() []error
- func (e Error) Context() interface{}
- func (e Error) Depth() uint
- func (e Error) Error() string
- func (e Error) ErrorWithDepth(depth int) error
- func (e Error) ErrorWithIndex(index int) error
- func (e Error) Format(ef string) string
- func (e Error) Is(target error) bool
- func (e Error) MarshalJSON() ([]byte, error)
- func (e Error) Trace() string
- func (e Error) Unwrap() error
- func (e Error) Walk(step func(err error) bool)
- type ErrorFormatToken
- type ErrorSeverity
- type ErrorSeverityLevel
- type Metadata
- type Process
Constants ยถ
This section is empty.
Variables ยถ
var ErrRegexRequired = errors.New("regex required")
ErrRegexRequired indicates that a regular expression is required.
var ErrSeverityAlreadyRegistered = errors.New("severity already registered")
ErrSeverityAlreadyRegistered indicates that the error severity has already been registered.
Functions ยถ
func RegisterErrorSeverity ยถ
func RegisterErrorSeverity(severity ErrorSeverity) error
RegisterErrorSeverity registers the error severity with the package. If the severity has already been registered, then a ErrSeverityAlreadyRegistered error is returned.
func ResetState ยถ
func ResetState()
ResetState resets the package's state to that at process launch.
func UnregisterErrorSeverity ยถ
func UnregisterErrorSeverity(severity ErrorSeverity)
UnregisterErrorSeverity unregisters the error severity from the package. If the severity wasn't already registered, then this function does nothing.
Types ยถ
type Caller ยถ
type Caller struct { // The caller's file. File string `json:"file"` // The caller's function name. Function string `json:"function"` // The caller's line number. Line int `json:"line"` // A stack trace of the goroutine that created the caller. StackTrace string `json:"stackTrace"` // Source returns raw source code around the line that the caller was created // on. This function will return an empty string if the process is not // currently being debugged. SourceFragment string `json:"sourceFragment"` }
Caller types contain call information.
type Configuration ยถ
type Configuration struct {
// contains filtered or unexported fields
}
Configuration types keep track of the package's configuration.
func (*Configuration) CaptureCaller ยถ
func (c *Configuration) CaptureCaller() bool
CaptureCaller gets a boolean that indicates whether or not new errors capture their caller information.
func (*Configuration) CaptureProcess ยถ
func (c *Configuration) CaptureProcess() bool
CaptureProcess gets a boolean that indicates whether or not new errors capture their process information.
func (*Configuration) CaptureSourceFragments ยถ
func (c *Configuration) CaptureSourceFragments() bool
CaptureSourceFragments gets a boolean that indicates whether or not new errors capture source fragments.
func (*Configuration) IgnoreBreakpoints ยถ
func (c *Configuration) IgnoreBreakpoints() bool
IgnoreBreakpoints returns whether or not calls to `Break` on `Process` types will be ignored. This value defaults to true.
func (*Configuration) MarshalMinimalJSON ยถ
func (c *Configuration) MarshalMinimalJSON() bool
MarshalMinimalJSON gets a boolean that indicates whether or not errors will be marshaled in to a minimal version of JSON.
func (*Configuration) NextErrorIndex ยถ
func (c *Configuration) NextErrorIndex() int
NextErrorIndex gets the next error index that will be used when creating an error.
func (*Configuration) Set ยถ
func (c *Configuration) Set( captureCaller bool, captureProcess bool, captureSourceFragments bool, sourceFragmentRadius int, ignoreBreakpoints bool, nextErrorIndex int, trackSimilarErrors bool, marshalMinimalJSON bool, )
Set configures the behavior of various aspects of the wrappederror package at once.
Configure individual properties using the Set(Property) methods.
func (*Configuration) SetCaptureCaller ยถ
func (c *Configuration) SetCaptureCaller(capture bool)
SetCaptureCaller sets a flag to determine if new errors capture their caller information.
func (*Configuration) SetCaptureProcess ยถ
func (c *Configuration) SetCaptureProcess(capture bool)
SetCaptureProcess sets a flag to determine if new errors capture their process information.
func (*Configuration) SetCaptureSourceFragments ยถ
func (c *Configuration) SetCaptureSourceFragments(capture bool)
SetCaptureSourceFragments sets a flag to determine whether or not new errors capture source fragments.
func (*Configuration) SetIgnoreBreakpoints ยถ
func (c *Configuration) SetIgnoreBreakpoints(ignore bool)
SetIgnoreBreakpoints tells all calls to `Break` on `Process` types to either handle or ignore invocations.
func (*Configuration) SetMarshalMinimalJSON ยถ
func (c *Configuration) SetMarshalMinimalJSON(minimal bool)
SetMarshalMinimalJSON determines how errors are marshaled in to JSON. When this value is true, a smaller JSON object is created without size-inflating data like stack traces and source fragments.
func (*Configuration) SetNextErrorIndex ยถ
func (c *Configuration) SetNextErrorIndex(index int)
SetNextErrorIndex sets the next error index that will be used when creating an error.
func (*Configuration) SetSourceFragmentRadius ยถ
func (c *Configuration) SetSourceFragmentRadius(radius int)
SetSourceFragmentRadius sets the radius of the source fragment obtained from source files at the line that the caller was created on.
func (*Configuration) SetTrackSimilarErrors ยถ
func (c *Configuration) SetTrackSimilarErrors(track bool)
SetTrackSimilarErrors enables or prohibits similar error tracking.
func (*Configuration) SourceFragmentRadius ยถ
func (c *Configuration) SourceFragmentRadius() int
SourceFragmentRadius gets the radius of source fragments obtained from source files.
func (*Configuration) TrackSimilarErrors ยถ
func (c *Configuration) TrackSimilarErrors() bool
TrackSimilarErrors returns whether or not similar errors are being tracked.
type Error ยถ
type Error struct { // The error's caller. // // Use this value to examine the error's call information such as file name, // function name, line number, stack trace and source fragment. // // Call information is captured by default. To not capture this information, // use the SetCaptureCaller configuration method. // // If call information is not captured, then this property is nil. Caller *Caller // Process information at the time the error was created. // // Use this value to examine the current process's information such as number // of goroutines, available logical CPUs, memory statistics, and so forth. // // Process information is captured by default. To not capture this // information, use the SetCaptureProcess configuration method. // // If process information is not captured, then this property is nil. Process *Process // Metadata pertaining to the error. // // Use this value to examine general properties about the error such as its // index, timestamp, and how many other similar errors have been created. // // Metadata is always captured, but some of its properties are configurable. Metadata *Metadata // contains filtered or unexported fields }
Error types wrap an error and provide context, caller and process information.
func (Error) As ยถ
As finds the first error in the error chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false.
func (Error) Depth ยถ
Depth returns the number of nested errors in the receiver. That is, the number of errors after, but not including, this error in the error chain.
For example, if an error has no nested errors, then its depth is 0.
func (Error) ErrorWithDepth ยถ
ErrorWithDepth returns the error in the chain with the given depth.
func (Error) ErrorWithIndex ยถ
ErrorWithIndex returns the error in the chain with the given index. This is the inverse index of depth.
For example, if the error chain is [e0, e1, e2] with depths [2, 1, 0], then the error at index 0 is e0, the error at index 1 is e1, and so forth.
func (Error) Format ยถ
Format returns a formatted string representation of the error using the error format string, ef.
You create an error format string by building a string with ErrorFormatToken types.
Do not use formatting verbs supported by the fmt package in the error format string.
func (Error) Is ยถ
Is reports whether any error in the error chain matches target.
The chain consists of the receiver followed by the sequence of errors obtained by repeatedly calling Unwrap.
The receiver considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
func (Error) MarshalJSON ยถ
MarshalJSON marshals the error in to JSON data.
type ErrorFormatToken ยถ
type ErrorFormatToken string
ErrorFormatToken types specify a token that can be used to format an error string.
const ( // ErrorFormatTokenContext prints the error's context. ErrorFormatTokenContext ErrorFormatToken = "${{CTX}}" // ErrorFormatTokenInner prints the error's context. ErrorFormatTokenInner ErrorFormatToken = "${{INN}}" // ErrorFormatTokenChain prints the error's context. ErrorFormatTokenChain ErrorFormatToken = "${{CHN}}" // ErrorFormatTokenFile prints the error's context. ErrorFormatTokenFile ErrorFormatToken = "${{FIL}}" // ErrorFormatTokenFunction prints the error's context. ErrorFormatTokenFunction ErrorFormatToken = "${{FUN}}" // ErrorFormatTokenLine prints the error's context. ErrorFormatTokenLine ErrorFormatToken = "${{LIN}}" // ErrorFormatTokenStack prints the error's context. ErrorFormatTokenStack ErrorFormatToken = "${{STK}}" // ErrorFormatTokenSource prints the error's context. ErrorFormatTokenSource ErrorFormatToken = "${{SRC}}" // ErrorFormatTokenTime prints the error's context. ErrorFormatTokenTime ErrorFormatToken = "${{TIM}}" // ErrorFormatTokenDuration prints the error's context. ErrorFormatTokenDuration ErrorFormatToken = "${{DUR}}" // ErrorFormatTokenIndex prints the error's context. ErrorFormatTokenIndex ErrorFormatToken = "${{IDX}}" // ErrorFormatTokenSimilar prints the error's context. ErrorFormatTokenSimilar ErrorFormatToken = "${{SIM}}" // ErrorFormatTokenRoutines prints the error's context. ErrorFormatTokenRoutines ErrorFormatToken = "${{RTS}}" // ErrorFormatTokenCPUs prints the error's context. ErrorFormatTokenCPUs ErrorFormatToken = "${{CPU}}" // ErrorFormatTokenCGO prints the error's context. ErrorFormatTokenCGO ErrorFormatToken = "${{CGO}}" // ErrorFormatTokenMemory prints the error's context. ErrorFormatTokenMemory ErrorFormatToken = "${{MEM}}" // ErrorFormatTokenSeverityTitle prints the error's severity title. ErrorFormatTokenSeverityTitle ErrorFormatToken = "${{SET}}" // ErrorFormatTokenSeverityLevel prints the error's severity level. ErrorFormatTokenSeverityLevel ErrorFormatToken = "${{SEL}}" )
A group of error format tokens.
type ErrorSeverity ยถ
type ErrorSeverity struct { // The severity's title. Title string `json:"title"` // The regular expression used to match against `Error` method strings. Regex *regexp.Regexp `json:"regex"` // The severity level. Level ErrorSeverityLevel `json:"level"` }
ErrorSeverity types define an error severity with a title, level, and a regular expression that is used to find matches in an error's `Error` method output.
func NewErrorSeverity ยถ
func NewErrorSeverity( title string, regex string, level ErrorSeverityLevel, ) (ErrorSeverity, error)
NewErrorSeverity creates and returns a new error severity with the given title, level and regular expression. If the regular expression is invalid, this function will return an error and an unknown error severity.
func (ErrorSeverity) String ยถ
func (s ErrorSeverity) String() string
type ErrorSeverityLevel ยถ
type ErrorSeverityLevel string
ErrorSeverityLevel types define an error severity level.
const ( ErrorSeverityLevelNone ErrorSeverityLevel = "none" ErrorSeverityLevelLow ErrorSeverityLevel = "low" ErrorSeverityLevelModerate ErrorSeverityLevel = "moderate" ErrorSeverityLevelHigh ErrorSeverityLevel = "high" ErrorSeverityLevelSevere ErrorSeverityLevel = "severe" )
A group of error severity levels.
type Metadata ยถ
type Metadata struct { // The time that the error was created. Time time.Time `json:"time"` // The duration since the process was launched and when the error was created. // // This value mimics the monotonic clock reading appended to the end of // strings returned by the `time.String() string` method. There will be a // slight difference in duration depending on the executable's package loading // order. Duration time.Duration `json:"duration"` // The index of the error. // // Error indexes begin at 1 and incriment for each error created during the // process's execution. // // To start at a different index, use the `SetNextErrorIndex` function. Index int `json:"index"` // The number of similar errors when this error was created. // // A similar error is an error that has the same inner error. A hashmap is // maintained of inner error `Error() string` value hashes. // // To turn this off, use the `SetTrackSimilarErrors` function. When tracking // is off, this method always returns 0. Similar int `json:"similar"` // The package automatically detects the severity of errors based on // ErrorSeverity instances registered through the package's configuration. Severity *ErrorSeverity `json:"severity,omitempty"` }
Metadata types contain metadata about an error.
type Process ยถ
type Process struct { // The number of go routines. Routines int `json:"goroutines"` // The number of available logical CPUs. CPUs int `json:"cpus"` // The number of cgo calls made by the process. CGO int `json:"cgos"` // Memory statistics about the process. Memory *runtime.MemStats `json:"memory,omitempty"` }
Process types contain process information at their time of creation.