Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateKeyword(e error) string
- func GetStack(e error) []string
- func GroupErrors(es ...error) error
- func IsError(src error, dest error) (string, bool)
- func JSON(e error, context map[string]interface{}) (string, []byte, error)
- func JSONIndent(e error, context map[string]interface{}, prefix, indent string) (string, []byte, error)
- func New(e error) error
- func NewFromStackTrace(stackTrace []string, msg string) error
- func NewFromString(msg string) error
- func NewFromStringWithAttach(msg string, attach interface{}) errordeprecated
- func NewFromStringWithAttachf(format string, msg string, attach interface{}) errordeprecated
- func NewFromStringWithDepth(msg string, depth int) error
- func NewFromStringWithHeader(msg string, header map[string]interface{}) error
- func NewFromStringWithHeaderf(format string, msg string, header map[string]interface{}) error
- func NewFromStringWithParam(msg string, params ...interface{}) error
- func NewFromStringf(format string, args ...interface{}) error
- func NewWithAttach(e error, msg interface{}) error
- func NewWithHeader(e error, header map[string]interface{}) error
- func NewWithParam(e error, params ...interface{}) errordeprecated
- func PrintStackFormat(flag int, file string, line int, cause string) string
- func ReGen(old error, new error) error
- func Split(s string, sub string) []string
- func Split2(s string, sub string, tmp *string, rs *[]string)
- func ToString(arg interface{}) string
- func Wrap(e error) error
- func WrapContext(e error, ctx map[string]interface{}) error
- type Error
- func (e Error) BasicError() string
- func (e Error) Error() string
- func (e Error) GenerateKeyword() string
- func (e Error) GetHeader(key string) string
- func (e Error) PrintStackTrace() string
- func (e *Error) SetHeader(key string, value string)
- func (e Error) Stack() []string
- func (e Error) StackTrace() string
- func (e Error) StackTraceValue() string
- func (e Error) String() string
- type Generator
- type Reporter
- func (r *Reporter) AddModeHandler(mode string, f func(e error, context map[string]interface{})) *Reporter
- func (r *Reporter) AddURL(mode string, url string) *Reporter
- func (r Reporter) DefaultHandler(e error, context map[string]interface{})
- func (r Reporter) JSON(e error, context map[string]interface{}) (string, []byte, error)
- func (r Reporter) JSONIndent(e error, context map[string]interface{}, prefix, indent string) (string, []byte, error)
- func (r *Reporter) Mode(mode string) *Reporter
- func (r Reporter) ReportURLHandler(e error, context map[string]interface{})
- func (r Reporter) SaveError(e error, context map[string]interface{}) string
- func (r *Reporter) SetContextName(name string)
- func (r *Reporter) SetMode(mode string)
- type ServiceError
- type UUID
Constants ¶
const ( LcauseBy = 1 << iota LdateTime Llongfile )
const Size = 16
Size of a UUID in bytes.
Variables ¶
var DefaultHandler = func(e error, context map[string]interface{}) { var tmp = make(map[string]interface{}, 0) tmp["error_uuid"] = context["error_uuid"] delete(context, "error_uuid") tmp["message"] = Wrap(e).Error() tmp["context"] = context var buf = []byte("") var er error buf, er = json.MarshalIndent(tmp, " ", " ") if er != nil { buf = []byte(Wrap(er).Error()) } fmt.Println(string(buf)) }
It will fmt error log into console.
Functions ¶
func JSONIndent ¶
func NewFromStackTrace ¶
new an error with existed stacktrace and generate the new error with new msg
func NewFromStringWithAttach
deprecated
func NewFromStringWithAttachf
deprecated
func NewFromStringWithDepth ¶
func NewFromStringWithHeader ¶
new an error from string with header
func NewFromStringWithHeaderf ¶
new a error from a well format string with header
func NewFromStringWithParam ¶
func NewFromStringf ¶
new a error from a well format string
func NewWithAttach ¶
func NewWithHeader ¶
New an error with header info
func NewWithParam
deprecated
func Wrap ¶
wrap an official error to Error type function do the same as New() New() or Wrap() depends on its semantics. mixing them is also correct.
func WrapContext ¶
Types ¶
type Error ¶
type Error struct { // basic E error StackTraces []string // Deprecated,保留了字段防止外部应用直接使用引起无法编译问题 // do not use context, it's tracking bug on development Context map[string]interface{} Header map[string][]string // upper ReGenerated bool Errors []error Flag int Keyword string // contains filtered or unexported fields }
an Error instance wraps an official error and storage its stackTrace. When tries to wrap the origin error to another, logic does like:
if er := f(); er!=nil{ log.Println(er.Error()) return errors.New("inner service error") }
'ReGenerated' should be set true and different errors should be saved in 'Errors',and the 'stackTrace' should include all stackTraces above.But in this case,'Error.E' only point to the origin one It's ok to storage both official error and 'Error'
func (Error) BasicError ¶
func (Error) GenerateKeyword ¶
generate an error key word. key word is used to help save errors in database It's suggested to set unique(date, keyword), when error with same keyword in a day,database only saves field 'times' rather than another error record
func (Error) PrintStackTrace ¶
print error stack trace e.Flag only controls 'Error' type or official error which has been wrapped to 'Error'. e.Flag only controls stack trace inner an Error type ,rather than some stack trace which has been init by api NewFromStackTrace([]string,string)
func (*Error) SetHeader ¶
set header for an error obj SetHeader is safe whether e.Header is nil or not
func (Error) StackTraceValue ¶
type Reporter ¶
type Reporter struct { Url map[string]string HandleMode map[string]func(e error, context map[string]interface{}) // contains filtered or unexported fields }
func NewReporter ¶
func (*Reporter) AddModeHandler ¶
func (Reporter) DefaultHandler ¶
func (Reporter) JSONIndent ¶
func (*Reporter) Mode ¶
Mode will clone a copy of reporter to avoid different goroutine using a unsafe clone
func (Reporter) ReportURLHandler ¶
rp.Mode related, should call like rp.Mode("dev").ReportURLHandler It will post error with context to an url storaged in reporter.Url
func (*Reporter) SetContextName ¶
type ServiceError ¶
func IsServiceErr ¶
func IsServiceErr(src error, dest ...error) (ServiceError, bool)
IsServiceErr is used to handle service error.
Case below will be regarded as service error and return se,true
func NewServiceError ¶
func NewServiceError(errmsg string, errcode int) ServiceError
func (ServiceError) Equal ¶
func (se ServiceError) Equal(dest ServiceError) bool
func (ServiceError) Error ¶
func (se ServiceError) Error() string
type UUID ¶
UUID representation compliant with specification described in RFC 4122.