Documentation ¶
Overview ¶
errkit implements all errors generated by nuclei and includes error definations specific to nuclei , error classification (like network,logic) etc
Index ¶
- Constants
- Variables
- func Append(errs ...error) error
- func As(err error, target interface{}) bool
- func Cause(err error) error
- func Combine(errs ...error) error
- func Errors(err error) []error
- func GetAttr(err error) []slog.Attr
- func GetAttrValue(err error, key string) slog.Value
- func Is(err error, target ...error) bool
- func IsDeadlineErr(err error) bool
- func IsKind(err error, match ...ErrKind) bool
- func IsNetworkPermanentErr(err error) bool
- func IsNetworkTemporaryErr(err error) bool
- func Join(errs ...error) error
- func ToSlogAttrGroup(err error) slog.Attr
- func ToSlogAttrs(err error) []slog.Attr
- func WithAttr(err error, attrs ...slog.Attr) error
- func WithMessage(err error, message string) error
- func WithMessagef(err error, format string, args ...interface{}) error
- func Wrap(err error, message string) error
- func Wrapf(err error, format string, args ...interface{}) error
- type CauseError
- type ComparableError
- type ErrKind
- type ErrorX
- func (e *ErrorX) Attrs() []slog.Attr
- func (e *ErrorX) Build() error
- func (e *ErrorX) Cause() error
- func (e *ErrorX) Error() string
- func (e *ErrorX) Errors() []error
- func (e *ErrorX) Is(err error) bool
- func (e *ErrorX) Kind() ErrKind
- func (e ErrorX) MarshalJSON() ([]byte, error)
- func (e *ErrorX) Msgf(format string, args ...interface{})
- func (e *ErrorX) ResetKind() *ErrorX
- func (e *ErrorX) SetAttr(s ...slog.Attr) *ErrorX
- func (e *ErrorX) SetKind(kind ErrKind) *ErrorX
- func (e *ErrorX) Unwrap() []error
- type JoinedError
- type WrappedError
Constants ¶
const ( // DelimArrow is delim used by projectdiscovery/utils to join errors DelimArrow = "<-" // DelimArrowSerialized DelimArrowSerialized = "\u003c-" // DelimSemiColon is standard delim popularly used to join errors DelimSemiColon = "; " // DelimMultiLine is delim used to join errors in multiline format DelimMultiLine = "\n - " // MultiLinePrefix is the prefix used for multiline errors MultiLineErrPrefix = "the following errors occurred:" )
Variables ¶
var ( // MaxErrorDepth is the maximum depth of errors to be unwrapped or maintained // all errors beyond this depth will be ignored MaxErrorDepth = env.GetEnvOrDefault("MAX_ERROR_DEPTH", 3) // ErrorSeperator is the seperator used to join errors ErrorSeperator = env.GetEnvOrDefault("ERROR_SEPERATOR", "; ") )
var ( // ErrClassNetwork indicates an error related to network operations // these may be resolved by retrying the operation with exponential backoff // ex: Timeout awaiting headers, i/o timeout etc ErrKindNetworkTemporary = NewPrimitiveErrKind("network-temporary-error", "temporary network error", isNetworkTemporaryErr) // ErrKindNetworkPermanent indicates a permanent error related to network operations // these may not be resolved by retrying and need manual intervention // ex: no address found for host ErrKindNetworkPermanent = NewPrimitiveErrKind("network-permanent-error", "permanent network error", isNetworkPermanentErr) // ErrKindDeadline indicates a timeout error in logical operations // these are custom deadlines set by nuclei itself to prevent infinite hangs // and in most cases are server side issues (ex: server connects but does not respond at all) // a manual intervention is required ErrKindDeadline = NewPrimitiveErrKind("deadline-error", "deadline error", isDeadlineErr) // ErrKindUnknown indicates an unknown error class // that has not been implemented yet this is used as fallback when converting a slog Item ErrKindUnknown = NewPrimitiveErrKind("unknown-error", "unknown error", nil) )
var ( // DefaultErrorKinds is the default error kinds used in classification // if one intends to add more default error kinds it must be done in init() function // of that package to avoid race conditions DefaultErrorKinds = []ErrKind{ ErrKindNetworkTemporary, ErrKindNetworkPermanent, ErrKindDeadline, } )
Functions ¶
func GetAttrValue ¶
GetAttrValue returns the value of the attribute with given key
func IsDeadlineErr ¶
IsDeadlineErr checks if given error is a deadline error
func IsKind ¶
IsKind checks if given error is equal to one of the given errkind if error did not already have a kind, it tries to parse it using default error kinds and given kinds
func IsNetworkPermanentErr ¶
IsNetworkPermanentErr checks if given error is a permanent network error
func IsNetworkTemporaryErr ¶
IsNetworkTemporaryErr checks if given error is a temporary network error
func Join ¶
Join joins given errors and returns a new error it ignores all nil errors Note: unlike Other libraries, Join does not use `\n` so it is equivalent to wrapping/Appending errors
func ToSlogAttrGroup ¶
ToSlogAttrGroup returns a slog attribute group for the given error it is in format of:
{ "data": { "kind": "<error-kind>", "cause": "<cause>", "errors": [ <errs>... ] } }
func ToSlogAttrs ¶
ToSlogAttrs returns slog attributes for the given error it is in format of:
{ "kind": "<error-kind>", "cause": "<cause>", "errors": [ <errs>... ] }
func WithAttr ¶
WithAttr wraps error with given attributes
err = errkit.WithAttr(err,slog.Any("resource",domain))
func WithMessagef ¶
WithMessagef
Types ¶
type CauseError ¶
type CauseError interface { // Cause return the original error that caused this without any wrapping Cause() error }
CauseError is implemented by errors that have a cause
type ComparableError ¶
type ComparableError interface { // Is checks if current error contains given error Is(err error) bool }
ComparableError is implemented by errors that can be compared
type ErrKind ¶
type ErrKind interface { // Is checks if current error kind is same as given error kind Is(ErrKind) bool // IsParent checks if current error kind is parent of given error kind // this allows heirarchical classification of errors and app specific handling IsParent(ErrKind) bool // RepresentsError checks if given error is of this kind Represents(*ErrorX) bool // Description returns predefined description of the error kind // this can be used to show user friendly error messages in case of error Description() string // String returns the string representation of the error kind String() string }
ErrKind is an interface that represents a kind of error
func CombineErrKinds ¶
CombineErrKinds combines multiple error kinds into a single error kind this is not recommended but available if needed It is currently used in ErrorX while printing the error It is recommended to implement a hierarchical error kind instead of using this outside of errkit
func GetAllErrorKinds ¶
GetAllErrorKinds returns all error kinds from the error this should not be used unless very good reason to do so
func GetErrorKind ¶
GetErrorKind returns the first error kind from the error extra error kinds can be passed as optional arguments
type ErrorX ¶
type ErrorX struct {
// contains filtered or unexported fields
}
ErrorX is a custom error type that can handle all known types of errors wrapping and joining strategies including custom ones and it supports error class which can be shown to client/users in more meaningful way
func FromError ¶
FromError parses a given error to understand the error class and optionally adds given message for more info
func (ErrorX) MarshalJSON ¶
func (*ErrorX) SetAttr ¶
SetAttr sets additional attributes to a given error it only adds unique attributes and ignores duplicates Note: only key is checked for uniqueness
type JoinedError ¶
type JoinedError interface { // Unwrap returns the underlying error Unwrap() []error }
JoinedError is implemented by errors that are joined by Join
type WrappedError ¶
type WrappedError interface { // Unwrap returns the underlying error Unwrap() error }
WrappedError is implemented by errors that are wrapped