Documentation ¶
Overview ¶
Package errorglue contains non-essential error declarations
Index ¶
- func ChainString(err error, format CSFormat) (s string)
- func DumpChain(err error) (typeNames string)
- func DumpGo(err error) (typeNames string)
- func ErrorChainSlice(err error) (errs []error)
- func ErrorList(err error) (errs []error)
- func ErrorsWithStack(err error) (errs []error)
- func FirstPanicStack(err error) (isPanic bool, stack pruntime.Stack, recoveryIndex, panicIndex int, ...)
- func GetInnerMostStack(err error) (stack pruntime.Stack)
- func GetStackTrace(err error) (stack pruntime.Stack)
- func GetStacks(err error) (stacks []pruntime.Stack)
- func IsMinusFlag(s fmt.State) bool
- func IsPlusFlag(s fmt.State) bool
- func IsQuoteVerb(r rune) bool
- func IsStringVerb(r rune) bool
- func IsValueVerb(r rune) bool
- func ListError(err error) (s string)
- func NewErrorData(err error, key, value string) (e2 error)
- func NewErrorStack(err error, st pruntime.Stack) (e2 error)
- func NewRelatedError(err, err2 error) (e2 error)
- func NewWarning(err error) error
- func RecoverThread(label string, onError func(err error))
- type CSFormat
- type ChainStringer
- type ErrorCallStacker
- type ErrorChain
- type ErrorHasCode
- type ErrorHasData
- type ErrorStore
- type RelatedError
- type RichError
- type SendNb
- type WarningType
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChainString ¶
ChainString() gets a string representation of a single error chain TODO 220319 finish comment
func DumpChain ¶
DumpChain retrieves a space-separated string of error implementation type-names found in the error chain of err. err can be nil
fmt.Println(Stack(errors.New("an error"))) *error116.errorStack *errors.errorString
func DumpGo ¶
DumpGo produces a newline-separated string of type-names and Go-syntax found in the error chain of err. err can be nil
func ErrorChainSlice ¶
ErrorChainSlice returns a slice of errors from a possible error chain. If err is nil, an empty slice is returned. If err does not have an error chain, a slice of only err is returned. Otherwise, the slice lists each error in the chain starting with err at index 0 ending with the oldest error of the chain
func ErrorList ¶
ErrorList returns the list of associated errors enclosed in all error chains of err
- the returned slice is a list of error chains beginning with the initial err
- If err is nil, a nil slice is returned
- duplicate error values are ignored
- order is:
- — associated errors from err’s error chain, oldest first
- — then associated errors from other error chains, oldest found error of each chain first, and errors from the last found error chain first
- —
- associated errors are independent error chains that allows a single error to enclose addditional errors not part of its error chain
- cyclic error values are filtered out so that no error instance is returned more than once
func ErrorsWithStack ¶
ErrorsWithStack gets all errors in the err error chain that has a stack trace. Oldest innermost stack trace is returned first. if not stack trace is present, the slice is empty
func FirstPanicStack ¶ added in v0.4.154
func FirstPanicStack(err error) ( isPanic bool, stack pruntime.Stack, recoveryIndex, panicIndex int, numberOfStacks int, errorWithStack error, )
FirstPanicStack checks all stack traces, oldest first, for a panic and returns:
- stack:
- — the panic stack if any
- — otherwise, the oldest stack if any
- — otherwise nil
- isPanic true: a panic stack was found
- — recoveryIndex panicIndex are valid
- numberOfStacks: the number of stacks until the panic stack including it, or the total number of stacks
- errorWithStack:
- — if panic, the error providing the oldest panic stack
- — otherwise, the oldest error with a stack
- — otherwise, the oldest error
- — otherwise nil
- this enables consumer to print:
- — panic location if any
- — otherwise, oldest error location if any
- — otherwise no location
- err is an error chain that may contain stack traces and be nil
- if any stack trace has a panic:
- — isPanic is true
- — stack is the oldest stack with a panic
- — stack[panicIndex] is the code line causing the oldest panic
- — stack[recoveryIndex] is the first code line in the deferred sequence. Typically the last line of the executing function
- — numberOfStacks is 1 for the panic stack and added the number of stacks that are older
- — errorWithStack is the error with panic, typically from [parl.Recover]
- if isPanic is false:
- — panicIndex recoveryIndex are zero
- — stack and errorWithStack is the oldest stack if any -— numberOfStacks is total number of stacks in the error chain
- this must be done beacuse maybe panic() was provided an error with stack trace
- on err nil: all values false, nil or zero
func GetInnerMostStack ¶
GetInnerMostStack gets the oldest stack trace in the error chain or nil if no stack trace is present
func GetStackTrace ¶
GetStackTrace gets the last stack trace
func IsMinusFlag ¶
IsMinusFlag determines if fmt.State has the '-' flag
func IsPlusFlag ¶
IsPlusFlag determines if fmt.State has the '+' flag
func IsQuoteVerb ¶
IsQuoteVerb determines if the rune corresponds to the %q quote verb
func IsStringVerb ¶
IsStringVerb determines if the rune corresponds to the %s string verb
func IsValueVerb ¶
IsValueVerb determines if the rune corresponds to the %v value verb
func NewErrorData ¶
NewErrorData returns an error containg a key/value pair
func NewErrorStack ¶
NewErrorStack attaches a stack to err
func NewRelatedError ¶
func NewWarning ¶
func RecoverThread ¶
RecoverThread is a defer function for threads. On panic, the onError function is invoked with an error message that contains location information
Types ¶
type CSFormat ¶
type CSFormat uint8
CSFormat describes string conversion of an error chain
- DefaultFormat ShortFormat LongFormat ShortSuffix LongSuffix
const ( // DefaultFormat is like printf %v, printf %s and error.Error() “message” // - data, stack traces and associated errors are not printed // - code location is not printed DefaultFormat CSFormat = iota + 1 // CodeLocation DefaultFormat with location added “message at runtime/panic.go:914” // - location is: // - — oldest panic code-line in any stack trace of err or its error chain // - — code-line creating the oldest error in err and its chain that has // a stack trace, when none of the errors hold a panic CodeLocation // ShortFormat has one-line location similar to printf %-v // - data, and stack traces are not printed // - associated errors are printed // - if the error or its chain contains a stack trace, a code location is output // - if any stack trace contains a panic, that oldest panic location is printed // - “error-message at error116.(*csTypeName).FuncName-chainstring_test.go:26” ShortFormat // LongFormat is similar to printf %+v. // - prints data, stack traces and associated errors // - if any stack trace contains a panic, that oldest panic location is printed after message // // output: // error-message // github.com/haraldrudell/parl/error116.(*csTypeName).FuncName // /opt/sw/privates/parl/error116/chainstring_test.go:26 // runtime.goexit // /opt/homebrew/Cellar/go/1.17.8/libexec/src/runtime/asm_arm64.s:1133 LongFormat // ShortSuffix is code-location “runtime/panic.go:914” // - no leading “ at ” // - if no stack is present, empty string ShortSuffix // LongSuffix full stack trace without message LongSuffix )
func PrintfFormat ¶
PrintfFormat gets the ErrorFormat to use when executing the Printf value verb 'v'
- %+v: LongFormat
- %-v: ShortFormat
- %v: DefaultFormat
type ChainStringer ¶
type ChainStringer interface { // ChainString is used by ChainStringer() to obtain comprehensive // string representations of errors. // The argument isIgnore() is used to avoid printing cyclic error values. // If a ChainStringer pointer receiver gets a nil value, the empty string is returned. // ChainString() obtains a string representation of the errors in its chain. // Rich errors implement either ChainStringer or fmt.Formatter ChainString(format CSFormat) string }
ChainStringer obntain s a comprehensive string representation of an error chain. formats used are DefaultFormat ShortFormat LongFormat ShortSuffix LongSuffix
type ErrorCallStacker ¶
ErrorCallStacker enrichens an error with a stack trace of code locations
type ErrorChain ¶
type ErrorChain struct {
// contains filtered or unexported fields
}
ErrorChain implements a chain of errors. Error chains do exist in the Go standard library but types and interfaces are not public. ErrorChain is used as an embedded type. ErrorChain’s publics are Error() and Unwrap()
ErrorChainSlice returns all errors of an error chain, or the chain can be traversed iteratively using errors.Unwrap()
func (*ErrorChain) Unwrap ¶
func (ec *ErrorChain) Unwrap() error
Unwrap is a method required to make ErrorChain an error chain ErrorChain.Unwrap() is used by errors.Unwrap() and ErrorChainSlice
type ErrorHasCode ¶
type ErrorHasCode interface { // Check if this error claims a particular Linux errno, an int IsErrno(errno int) (hasErrno bool) // ErrorCode determines if this error claims code, a string ErrorCode(code string) (hasCode bool) // ErrorCodes returns codes that this error claims, some are numeric strings mapping to an errno ErrorCodes(codes []string) (has []string) }
ErrorHasCode allows an error to classify itself
type ErrorHasData ¶
type ErrorHasData interface {
KeyValue() (key, value string)
}
ErrorHasData enrichens an error with key and value strings
type ErrorStore ¶
type ErrorStore interface { AddError(err error) (e error) GetError() (e error) InvokeIfError(fn func(err error)) Error() (message string) }
ErrorStore is a thread-safe store for any number of errors
type RelatedError ¶
type RelatedError interface {
AssociatedError() (error error)
}
RelatedError enrichens an error with an enclosed additional error value
type RichError ¶
type RichError struct {
ErrorChain
}
RichError is an error chain that behaves like fmt.Formatter. this allows for custom print-outs using %+v and %-v RichError has publics Error() Unwrap() Format()
type SendNb ¶
type SendNb struct {
// contains filtered or unexported fields
}
SendNb implements non-blocking send using a thread and buffer up to size of int
func (*SendNb) HasChannel ¶
func (*SendNb) IsShutdown ¶
type WarningType ¶
type WarningType struct {
ErrorChain
}
warningType is an error with lesser impact
func (*WarningType) Error ¶
func (w *WarningType) Error() (s string)
Error prepends “Warning: ” to the error message