package serr
import "fmt"
var (
ErrNone error = nil
ErrUndefined = NewError(E_ERROR_UNDEFINED, "undefined")
)
const (
E_ERROR_NONE uint64 = iota
E_ERROR_UNDEFINED
)
func NewError(code uint64, message string, args ...interface{}) error {
if code == 0 {
return nil
}
return &_Error{code: code, message: fmt.Sprintf(message, args...)}
}
func AssignError(code uint64, err error) error {
if err == nil {
return nil
}
if se, ok := err.(_Error); ok {
return &_Error{code: code, message: se.message}
}
return &_Error{code: code, message: err.Error()}
}
type _Error struct {
code uint64
message string
}
func (e _Error) Error() string {
return fmt.Sprintf("[%d] %s", e.code, e.message)
}