Documentation ¶
Index ¶
- Constants
- func Blame(msg string, description ...interface{}) error
- func DeadCanary(msg string, description ...interface{}) error
- func E(msg string, description ...interface{}) error
- func ErrorWithStack(errChain error) string
- func Errorf(format string, args ...interface{}) error
- func FailCaller(msg string, skipFrames int) error
- func FailHere(msg string) error
- func Fatal(msg string, description ...interface{}) error
- func FindDetail(value error, target interface{}) bool
- func Fraud(msg string, description ...interface{}) error
- func IllegalState() error
- func IllegalValue() error
- func Impossible() error
- func IsEqual(err0, err1 error) bool
- func IsInSystemPanic(skipFrames int) bool
- func JoinStackText(s0 string, s1 StackTrace) string
- func LocalBreach(msg string, description ...interface{}) error
- func MinimizeDebugStack(stackTrace []byte, boundPackage string, includeBoundary bool) []byte
- func MinimizePanicStack(stackTrace []byte, boundPackage string, includeBoundary bool) []byte
- func New(msg string, description ...interface{}) error
- func NewDescription(description interface{}) error
- func NewFmt(msg string, errorDescription interface{}, fmtFn FormatterFunc) error
- func NotImplemented() error
- func Print(errChain error) string
- func PrintTo(errChain error, includeStack bool, b *strings.Builder)
- func R(recovered interface{}, prevErr error) error
- func RW(recovered interface{}, prevErr error, msg string, description ...interface{}) error
- func RWn(recovered interface{}, prevErr error, msg string, details ...interface{}) error
- func RemoteBreach(msg string, description ...interface{}) error
- func Rn(recovered interface{}, prevErr error) error
- func SetFormatter(fn FormatterFunc)
- func Severe(severity Severity, msg string, description ...interface{}) error
- func TrimStackTrace(s string) string
- func Unsupported() error
- func Violation(msg string, description ...interface{}) error
- func W(err error, msg string, description ...interface{}) error
- func Walk(errChain error, fn func(error, StackTraceHolder) bool) bool
- func WithDefaultSeverity(err error, s Severity) error
- func WithDetails(predecessor error, details ...interface{}) error
- func WithEscalatedSeverity(err error, s Severity) error
- func WithSeverity(err error, s Severity) error
- func WithStack(err error) error
- func WithStackAndDetails(predecessor error, details interface{}) error
- func WithStackExt(err error, skipFrames int) error
- func WithStackTop(err error) error
- func WithStackTopExt(err error, skipFrames int) error
- func WrapPanic(recovered interface{}) error
- func WrapPanicExt(recovered interface{}, skipFrames int) error
- func WrapPanicNoStack(recovered interface{}) error
- func Wrapf(err error, format string, args ...interface{}) error
- type DeepestStackMode
- type FormatterFunc
- type PanicHolder
- type Severity
- type StackCompareMode
- type StackRelation
- type StackTrace
- func CaptureStack(skipFrames int) StackTrace
- func CaptureStackTop(skipFrames int) StackTrace
- func DeepestStackTraceOf(errChain error) StackTrace
- func ErrorWithTopOrFullStack(errChain error) (string, StackTrace)
- func ErrorWithTopOrMinimizedStack(errChain error, boundPackage string, includeBoundary bool) (string, StackTrace)
- func ExtractStackTop(st StackTrace, skipFrames int) StackTrace
- func MinimizeStackTrace(st StackTrace, boundPackage string, includeBoundary bool) StackTrace
- type StackTraceHolder
- func InnermostFullStack(errChain error) (sth StackTraceHolder)
- func InnermostStack(errChain error) (sth StackTraceHolder)
- func NearestStackOf(errChain, target error) (error, StackTraceHolder, bool)
- func OutermostStack(errChain error) StackTraceHolder
- func StackOf(errChain, target error) (error, StackTraceHolder, bool)
Constants ¶
const NoStackTrace int = math.MaxInt32
const StackTracePrefix = "Stack trace:"
Variables ¶
This section is empty.
Functions ¶
func DeadCanary ¶
func E ¶
E creates an error by the provided message and description. Description can be a log structure
func ErrorWithStack ¶
func FailCaller ¶
FailCaller creates an error that captures the entry of caller's stack after skipping (skipFrames).
func FindDetail ¶
func IllegalState ¶
func IllegalState() error
IllegalState is to indicate that an internal state of a function/object is incorrect or unexpected This error captures the topmost entry of caller's stack.
func IllegalValue ¶
func IllegalValue() error
IllegalValue is to indicate that an argument provided to a calling function is incorrect This error captures the topmost entry of caller's stack.
func Impossible ¶
func Impossible() error
Impossible is to indicate that the point can never be reached. This error captures the topmost entry of caller's stack.
func IsEqual ¶
IsEqual does panic-safe comparison of error values. Incomparable values will always return false. It uses Is() on both sides
func IsInSystemPanic ¶
func JoinStackText ¶
func JoinStackText(s0 string, s1 StackTrace) string
func LocalBreach ¶
func MinimizeDebugStack ¶
func MinimizePanicStack ¶
func New ¶
New creates an error with the given message text and description. Log structs can be used
func NewDescription ¶
func NewDescription(description interface{}) error
NewDescription creates an error with the given description. Log structs can be used
func NewFmt ¶
func NewFmt(msg string, errorDescription interface{}, fmtFn FormatterFunc) error
func NotImplemented ¶
func NotImplemented() error
NotImplemented is to indicate that a calling function was not yet implemented, but it is expected to be completed soon This error captures the topmost entry of caller's stack.
func PrintTo ¶
PrintTo calls Walk() and builds a full list of errors and corresponding stacks in the chain.
func R ¶
R takes recovered panic and previous error if any, then wraps them together with current stack Returns (prevErr) when (recovered) is nil. NB! Must be called inside defer, e.g. defer func() { err = R(recover(), err) } ()
func RW ¶
RW takes recovered panic, previous error if any, then wraps them together with current stack and message. Returns (prevErr) when (recovered) is nil. Description can be a log structure NB! Must be called inside defer, e.g. defer func() { err = RW(recover(), err, "msg", x) } ()
func RWn ¶
Rn takes recovered panic, previous error if any, then wraps them together with current stack and message. But without a panic mark. NB! Must be called inside defer, e.g. defer func() { err = RWn(recover(), err, "msg", x) } ()
func RemoteBreach ¶
func Rn ¶
Rn takes recovered panic and reports it as an error, without a panic mark. Result is wrapped with current stack. NB! Must be called inside defer, e.g. defer func() { err = Rn(recover(), err) } ()
func SetFormatter ¶
func SetFormatter(fn FormatterFunc)
SetFormatter sets a formatter to be applied by NewDescription and New
func TrimStackTrace ¶
func Unsupported ¶
func Unsupported() error
Unsupported is to indicate that a calling function is unsupported intentionally and will remain so for awhile This error captures the topmost entry of caller's stack.
func Walk ¶
func Walk(errChain error, fn func(error, StackTraceHolder) bool) bool
Walks through the given error chain and call (fn) for each entry, does unwrapping for stack trace data.
func WithDefaultSeverity ¶
func WithDetails ¶
func WithEscalatedSeverity ¶
func WithSeverity ¶
func WithStackAndDetails ¶
func WithStackExt ¶
WithStackExt wraps the error with stack with the given number of frames skipped. Nil value will return nil.
func WithStackTop ¶
WithStackTop wraps the error with stack's topmost entry only. Nil value will return nil. Use this method to augment an error specific to a code location.
func WithStackTopExt ¶
WithStackTopExt wraps the error with stack's topmost entry after skipping the given number of frames. Nil value will return nil.
func WrapPanic ¶
func WrapPanic(recovered interface{}) error
WrapPanic returns an error for the given recovered panic with a stack trace. The error is also marked as recovered panic. Will return nil for a nil value NB! Should be used inside a defer.
func WrapPanicExt ¶
WrapPanicNoStack returns an error for the given recovered panic with or without a stack trace. When (skipFrames) = NoStackTrace then no stack trace is included. The error is also marked as recovered panic. Will return nil for a nil value
func WrapPanicNoStack ¶
func WrapPanicNoStack(recovered interface{}) error
WrapPanicNoStack returns an error for the given recovered panic without a stack trace. The error is also marked as recovered panic. Will return nil for a nil value NB! Should be used inside a defer.
Types ¶
type DeepestStackMode ¶
type DeepestStackMode uint8
const ( InheritedTrace DeepestStackMode SupersededTrace )
type FormatterFunc ¶
func GetFormatter ¶
func GetFormatter() FormatterFunc
type PanicHolder ¶
type PanicHolder interface { StackTraceHolder Recovered() interface{} }
PanicHolder is a marker interface for a recovered panic
func InnermostPanicWithStack ¶
func InnermostPanicWithStack(errorOrHolder interface{}) PanicHolder
InnermostPanicWithStack returns the most distant panic holder from the chain. The value can be either error or PanicHolder. Otherwise will return nil.
type Severity ¶
type Severity uint8
const ( // NormalSeverity should only be used to override higher severity levels with WithSeverity NormalSeverity Severity // BlameSeverity indicates an attempt of a remote peer to compromise stability/performance of a peer network, // but there is no non-reputable proof available/possible, or multiple evidences from multiple peers are required. BlameSeverity // ViolationSeverity indicates an attempt of a remote peer to use an incorrect encoding / protocol combination that // can't compromise stability or performance of a peer network. ViolationSeverity // FraudSeverity indicates an attempt of a remote peer to compromise stability/performance of a peer network. // This severity can only be declared when there is either a non-reputable proof or a network majority proof. FraudSeverity // RemoteBreachSeverity indicates a presence of either security breach on a remote peer or MitM attack. // Connection to the peer must be terminated, and the peer may need to be quarantined / blacklisted. RemoteBreachSeverity // LocalBreachSeverity indicates a presence of local security breach. Application must be terminated or quarantined asap. LocalBreachSeverity // FatalSeverity indicates an error that requires an application to be terminated asap for a reason unknown. FatalSeverity )
func GetSeverity ¶
func SeverityOf ¶
func UnwrapExtraInfo ¶
func (Severity) IsCompromised ¶
func (Severity) IsDeadCanary ¶
func (Severity) IsFraudOrWorse ¶
type StackCompareMode ¶
type StackCompareMode uint8
StackCompareMode defines precision of stack trace comparison
const ( StrictMatch StackCompareMode = iota SameLine SameMethod )
type StackRelation ¶
type StackRelation int8
StackRelation shows relevance of 2 stacks
const ( SubsetStack StackRelation = iota - 2 StackTop EqualStack FullStack // vs StackTop SupersetStack // vs SubsetStack DifferentStack )
func CompareDebugStackTrace ¶
func CompareDebugStackTrace(bst0, bst1 []byte, mode StackCompareMode) StackRelation
CompareDebugStackTrace returns a relation between the stacks produced by debug.Stack() with the given mode/precision.
func CompareStackTrace ¶
func CompareStackTrace(st0, st1 StackTrace) StackRelation
CompareStackTrace returns a relation between the given stacks. Only supports StackTrace instances created by this module, otherwise will return DifferentStack
func CompareStackTraceExt ¶
func CompareStackTraceExt(st0, st1 StackTrace, mode StackCompareMode) StackRelation
CompareStackTraceExt returns a relation between the given stacks with the given mode/precision. Only supports StackTrace instances created by this module, otherwise will return DifferentStack
type StackTrace ¶
type StackTrace interface { StackTraceAsText() string WriteStackTraceTo(writer io.Writer) error IsFullStack() bool }
func CaptureStack ¶
func CaptureStack(skipFrames int) StackTrace
CaptureStack captures whole stack When (skipFrames) are more than stack depth then only "created by" entry will be returned
func CaptureStackTop ¶
func CaptureStackTop(skipFrames int) StackTrace
CaptureStackTop is an optimized version to capture a limited info about top-level stack entry only When (skipFrames) are more than stack depth then only "created by" entry will be returned
func DeepestStackTraceOf ¶
func DeepestStackTraceOf(errChain error) StackTrace
func ErrorWithTopOrFullStack ¶
func ErrorWithTopOrFullStack(errChain error) (string, StackTrace)
func ErrorWithTopOrMinimizedStack ¶
func ErrorWithTopOrMinimizedStack(errChain error, boundPackage string, includeBoundary bool) (string, StackTrace)
func ExtractStackTop ¶
func ExtractStackTop(st StackTrace, skipFrames int) StackTrace
func MinimizeStackTrace ¶
func MinimizeStackTrace(st StackTrace, boundPackage string, includeBoundary bool) StackTrace
type StackTraceHolder ¶
type StackTraceHolder interface { // Cause returns a cause for this stack trace. It can NOT be used like Unwrap() as it may return self. Cause() error // ShallowStackTrace returns a stack trace registered for this cause ShallowStackTrace() StackTrace // DeepestStackTrace returns this or the deepest stack trace from cause's error chain that embeds ShallowStackTrace. // Bool value is true when the stack trace was inherited from the cause. DeepestStackTrace() (StackTrace, DeepestStackMode) }
func InnermostFullStack ¶
func InnermostFullStack(errChain error) (sth StackTraceHolder)
InnermostFullStack returns the most distant StackTraceHolder with non-nil ShallowStackTrace and IsFullStack from errChain
func InnermostStack ¶
func InnermostStack(errChain error) (sth StackTraceHolder)
InnermostStack returns the most distant StackTraceHolder with non-nil ShallowStackTrace from errChain
func NearestStackOf ¶
func NearestStackOf(errChain, target error) (error, StackTraceHolder, bool)
NearestStackOf returns a target-matched entry with a last encountered StackTraceHolder with a either shallow or deep non-nil stack (optional) When (target) is nil - returns the last error of the chain When (target) is not found, returns only the last StackTraceHolder. nolint
func OutermostStack ¶
func OutermostStack(errChain error) StackTraceHolder
OutermostStack returns the closest StackTraceHolder with non-nil ShallowStackTrace from errChain