Documentation ¶
Overview ¶
Package errorglue contains helful declarations that are not important
Index ¶
- func ChainString(err error, format ErrorFormat) (s string)
- func DumpChain(err error) (typeNames string)
- func ErrorChainSlice(err error) (errs []error)
- func ErrorsWithStack(err error) (errs []error)
- 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 NewErrorData(err error, key, value string) (e2 error)
- func NewErrorStack(err error, st StackSlice) (e2 error)
- func NewRelatedError(err, err2 error) (e2 error)
- func NewWarning(err error) error
- type ChainStringer
- type ErrorCallStacker
- type ErrorChain
- type ErrorFormat
- type ErrorHasCode
- type ErrorHasData
- type RelatedError
- type RichError
- type StackSlice
- type WarningType
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChainString ¶
func ChainString(err error, format ErrorFormat) (s string)
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 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 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 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 ¶
func NewErrorStack ¶
func NewErrorStack(err error, st StackSlice) (e2 error)
func NewRelatedError ¶
func NewWarning ¶
Types ¶
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 ErrorFormat) string }
ChainStringer obntain s a comprehensive string representation of an error chain. formats used are DefaultFormat ShortFormat LongFormat ShortSuffix LongSuffix
type ErrorCallStacker ¶
type ErrorCallStacker interface {
StackTrace() StackSlice
}
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 NewErrorChain ¶
func NewErrorChain(err error) (e2 *ErrorChain)
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 ErrorFormat ¶
type ErrorFormat byte
ErrorFormat describes string conversion of an error chain
const ( // DefaultFormat is similar to printf %v, printf %s and error.Error(). // For an error with data, stack trace and associated errors, // DefaultFormat only prints the error message: // error-message DefaultFormat ErrorFormat = iota + 1 // ShortFormat has one-line location similar to printf %-v. // ShortFormat does not print stack traces, data and associated errors. // ShortFormat does print a one-liner of the error message and a brief code location: // error-message at error116.(*csTypeName).FuncName-chainstring_test.go:26 ShortFormat // LongFormat is similar to printf %+v. // ShortFormat does not print stack traces, data and associated errors. // 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 one-line without message ShortSuffix // LongSuffix full stack trace without message LongSuffix )
func PrintfFormat ¶
func PrintfFormat(s fmt.State) ErrorFormat
PrintfFormat gets the ErrorFormat to use when executing the Printf value verb 'v'
type ErrorHasCode ¶
type ErrorHasCode interface { error ErrorCode(code string) (hasCode bool) 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 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()
func NewRichError ¶
type StackSlice ¶
type StackSlice []runt.CodeLocation
StackSlice represents a StackSlice of program counters.
func GetInnerMostStack ¶
func GetInnerMostStack(err error) (stack StackSlice)
GetInnerMostStack gets the oldest stack trace in the error chain
func GetStackTrace ¶
func GetStackTrace(err error) (stack StackSlice)
GetStackTrace gets the last stack trace
func GetStacks ¶
func GetStacks(err error) (stacks []StackSlice)
GetStacks gets a slice of all stack traces, oldest first
func NewStackSlice ¶
func NewStackSlice(skip int) (slice StackSlice)
NewStackSlice gets a slice of stack frames
func (StackSlice) Clone ¶
func (st StackSlice) Clone() (s StackSlice)
func (StackSlice) Format ¶
func (st StackSlice) Format(s fmt.State, verb rune)
Format implements fmt.Formatter
func (StackSlice) Short ¶
func (st StackSlice) Short() (s string)
func (StackSlice) String ¶
func (st StackSlice) String() (s string)
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