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.
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
// error system package
|
|
package icserror
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
type IcsError struct {
|
|
code interface{}
|
|
message string
|
|
err error
|
|
}
|
|
|
|
// Error implements error.
|
|
func (e *IcsError) Error() string {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
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) String() string {
|
|
return fmt.Sprintf("Message: %s, Code: %v, Error: %v\n", e.message, e.code, 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
|
|
}
|