Documentation ¶
Index ¶
- Variables
- func AddParent(errobj ErrorObject, parent ErrorObject) error
- func AddRuntimeCallerFilter(filters ...runtimecaller.Filter)
- func AllNamedFactories() map[string]ErrorFactory
- func ContainErrorFunc(err error, equalFunc func(error) bool) bool
- func Length(base ErrorObject) int
- func MarshalJSON(errobj error) ([]byte, error)
- func RuntimeCaller(skip int, extraFilters ...runtimecaller.Filter) (callinfo runtimecaller.CallInfo, ok bool)
- func RuntimeCallerFilterStopErrutilPackage(callinfo runtimecaller.CallInfo) (valid bool, stop bool)
- func RuntimeCallerFilterStopSQLUtilPackage(callinfo runtimecaller.CallInfo) (valid bool, stop bool)
- func SetDefaultLogger(logger LoggerType)
- func Trace(errin error)
- func TraceSkip(errin error, skip int)
- func TraceWrap(errin error, wraperr error)
- func WalkErrors(base ErrorObject, walkFunc WalkFunc) (err error)
- func WriteCallInfo(output io.Writer, callinfo runtimecaller.CallInfo, longFile bool, line bool, ...) (n int, err error)
- type ConsoleFormatter
- type ErrorFactory
- type ErrorFormatter
- type ErrorJSON
- type ErrorObject
- type JSONFormatter
- type LoggerOptions
- type LoggerType
- type TraceFormatter
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultRuntimeCallerFilter = []runtimecaller.Filter{}
DefaultRuntimeCallerFilter use for filter error stack info
var (
ErrorWalkLoop = NewFactory("detect error component parents loop when walking")
)
errors
Functions ¶
func AddParent ¶
func AddParent(errobj ErrorObject, parent ErrorObject) error
AddParent add parent to errobj
func AddRuntimeCallerFilter ¶
func AddRuntimeCallerFilter(filters ...runtimecaller.Filter)
AddRuntimeCallerFilter add filters to DefaultRuntimeCallerFilter for RuntimeCaller()
func AllNamedFactories ¶
func AllNamedFactories() map[string]ErrorFactory
AllNamedFactories return all named factories
func ContainErrorFunc ¶
ContainErrorFunc check error contain error by custom equalFunc
func Length ¶
func Length(base ErrorObject) int
Length count number of ErrorObject and all parents, return -1 if error
func RuntimeCaller ¶
func RuntimeCaller(skip int, extraFilters ...runtimecaller.Filter) (callinfo runtimecaller.CallInfo, ok bool)
RuntimeCaller wrap runtimecaller.GetByFilters() with DefaultRuntimeCallerFilter
func RuntimeCallerFilterStopErrutilPackage ¶
func RuntimeCallerFilterStopErrutilPackage(callinfo runtimecaller.CallInfo) (valid bool, stop bool)
RuntimeCallerFilterStopErrutilPackage filter CallInfo to stop after reach KDGoLib/errutil package
func RuntimeCallerFilterStopSQLUtilPackage ¶
func RuntimeCallerFilterStopSQLUtilPackage(callinfo runtimecaller.CallInfo) (valid bool, stop bool)
RuntimeCallerFilterStopSQLUtilPackage filter CallInfo to stop after reach KDGoLib/sqlutil package
func SetDefaultLogger ¶
func SetDefaultLogger(logger LoggerType)
SetDefaultLogger set default LoggerType
func Trace ¶
func Trace(errin error)
Trace error stack, output to default ErrorFormatter, panic if output error
func TraceSkip ¶
TraceSkip error stack, output to default ErrorFormatter, skip n function calls, panic if output error
func WalkErrors ¶
func WalkErrors(base ErrorObject, walkFunc WalkFunc) (err error)
WalkErrors walk from base error through all parents return ErrorWalkLoop if detected loop
Types ¶
type ConsoleFormatter ¶
type ConsoleFormatter struct { // seperator between errors, e.g. "; " will output "err1; err2; err3" Seperator string // output timestamp for prefix, e.g. "2006-01-02 15:04:05 " TimeFormat string // show error position with long filename LongFile bool // show error position with short filename ShortFile bool // show error position with line number, work with LongFile or ShortFile Line bool // replace package name for securify ReplacePackages map[string]string }
ConsoleFormatter used to format error object in console readable
func NewConsoleFormatter ¶
func NewConsoleFormatter(seperator string) *ConsoleFormatter
NewConsoleFormatter create JSONErrorFormatter instance
func (*ConsoleFormatter) Format ¶
func (t *ConsoleFormatter) Format(errin error) (errtext string, err error)
Format error object
func (*ConsoleFormatter) FormatSkip ¶
func (t *ConsoleFormatter) FormatSkip(errin error, skip int) (errtext string, err error)
FormatSkip trace error line and format object
type ErrorFactory ¶
type ErrorFactory interface { Error() string Name() string New(err error, params ...interface{}) ErrorObject Match(err error) bool In(err error) bool }
ErrorFactory is used for create or check ErrorObject
func AllSortedNamedFactories ¶
func AllSortedNamedFactories() []ErrorFactory
AllSortedNamedFactories return all sorted named factories NOTE: this is slow for sorting in runtime
func FactoryOf ¶
func FactoryOf(err error) ErrorFactory
FactoryOf return factory of error, return nil if not factory found
func NewFactory ¶
func NewFactory(errtext string) ErrorFactory
NewFactory return new ErrorFactory instance
func NewNamedFactory ¶
func NewNamedFactory(name string, errtext string) ErrorFactory
NewNamedFactory return new ErrorFactory instance with factory name, panic if name duplicated
type ErrorFormatter ¶
ErrorFormatter to format error
type ErrorJSON ¶
type ErrorJSON struct { ErrorPath string `json:"errorpath,omitempty"` ErrorMsg string `json:"error,omitempty"` ErrorMsgs []string `json:"errors,omitempty"` ErrorFactories map[string]bool `json:"errfac,omitempty"` }
ErrorJSON is a helper struct for display error
type ErrorObject ¶
type ErrorObject interface { Error() string Factory() ErrorFactory Parent() ErrorObject SetParent(parent ErrorObject) ErrorObject runtimecaller.CallInfo }
ErrorObject is a rich error interface
func NewErrors ¶
func NewErrors(errs ...error) ErrorObject
NewErrors return ErrorObject that contains all input errors
func NewErrorsSkip ¶
func NewErrorsSkip(skip int, errs ...error) ErrorObject
NewErrorsSkip return ErrorObject, skip function call
type JSONFormatter ¶
type JSONFormatter struct{}
JSONFormatter used to format error to json
func NewJSONFormatter ¶
func NewJSONFormatter() *JSONFormatter
NewJSONFormatter create JSONFormatter instance
func (*JSONFormatter) Format ¶
func (t *JSONFormatter) Format(errin error) (errtext string, err error)
Format error to json
func (*JSONFormatter) FormatSkip ¶
func (t *JSONFormatter) FormatSkip(errin error, skip int) (errtext string, err error)
FormatSkip trace error line and format to json
type LoggerOptions ¶
type LoggerOptions struct { DefaultOutput io.Writer ErrorOutput io.Writer HideFile bool ShortFile bool HideLine bool ReplacePackages map[string]string TraceFormatter TraceFormatter }
LoggerOptions for Logger
type LoggerType ¶
type LoggerType interface { Debug(v ...interface{}) Print(v ...interface{}) Error(v ...interface{}) Trace(errin error) TraceSkip(errin error, skip int) }
LoggerType declare general log types
type TraceFormatter ¶
type TraceFormatter interface { ErrorFormatter FormatSkip(errin error, skip int) (string, error) }
TraceFormatter to trace error occur line formatter
type WalkFunc ¶
type WalkFunc func(errcomp ErrorObject) (stop bool, err error)
WalkFunc is a callback for WalkErrors