You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
voicebot/icserror/icserror.go

67 lines
1.2 KiB
Go

3 years ago
//error system package
package icserror
import (
"errors"
"fmt"
"runtime"
"strings"
)
type IcsError struct {
code interface{}
message string
err error
}
func GetModName() string {
return "icserror"
}
func NewIcsError(errString string, code interface{}) *IcsError {
var err IcsError
err.err = errors.New(errString)
err.code = code
err.message = errString
return &err
}
func (e IcsError) Print() {
fmt.Printf("Code: %v, Message: %s, Error: %v\n", e.code, e.message, e.err)
}
func (e IcsError) PrintWithCaller(depth int) {
errstr := fmt.Sprintf("Code: %v, Message: %s", e.code, e.message)
funcname, file, line, ok := runtime.Caller(depth)
if ok {
files := strings.Split(file, "/")
fileslen := len(files)
func1 := runtime.FuncForPC(funcname).Name()
funcs := strings.Split(func1, "/")
funcslen := len(funcs)
fmt.Printf("[%s:%d %s] %s\n", files[fileslen-1], line, funcs[funcslen-1], errstr)
}
}
func (e IcsError) Equal(i *IcsError) bool {
return e.code == i.code
}
func (e *IcsError) SetError(baseError error) {
e.err = baseError
}
func (e *IcsError) GetCode() interface{} {
return e.code
}
func (e *IcsError) GetMessage() string {
return e.message
}
func (e *IcsError) GetError() error {
return e.err
}