2 Star 6 Fork 5

Plato / rpc-go-backend

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
errors.go 2.90 KB
一键复制 编辑 原始数据 按行查看 历史
CloudGuan 提交于 2023-10-10 12:57 . !16ISSUE: async rpc call result
package errors
import (
gerror "errors"
"fmt"
)
type RpcErrorCode uint32
const (
RpcNoErr RpcErrorCode = iota
CommErr
TransportClosed
ProxyNotExist
ProxyDisconnected
ProxyTimeout
ProxyCallNoFound
StubCallInvalid
ServiceShutdown
ServiceNotExist
ServiceHasExist
MethodException
ServicePanic
SERVICE_NOT_FOUND
FUNCTION_NOT_FOUND
)
var (
ErrRpcNotFound = gerror.New("rpc service or method not found")
ErrRpcTimeOut = gerror.New("rpc proxy call time out")
ErrRpcRet = gerror.New("rpc method execute return error")
ErrRpcNotInit = gerror.New("rpc framework not init")
ErrRpcCallFinished = gerror.New("rpc call has been finished")
ErrRpcClosed = gerror.New("rpc has been closed")
ErrInvalidProto = gerror.New("invalid rpc protocol")
ErrServiceInit = gerror.New("initialize service error")
ErrInvalidSubCtx = gerror.New("invalid subscribe params")
ErrRepeatedSub = gerror.New("repeated subscribe for service ")
ErrServiceNotFound = gerror.New("service not founded")
ErrInvalidPublisher = gerror.New("invalid publisher")
)
var (
ErrTransClose = &RpcError{TransportClosed, "Transport has been closed"}
ErrProxyInvalid = &RpcError{ProxyNotExist, "Proxy Is Invalid"}
ErrStubCallInvalid = &RpcError{StubCallInvalid, "stub's call invalid"}
ErrServicePanic = &RpcError{ServicePanic, "service exec panic"}
ErrIllegalReq = &RpcError{errCode: CommErr, errStr: "invalid request message!"}
ErrIllegalProto = &RpcError{errCode: CommErr, errStr: "rpc protocol message buffer error !"}
ErrMsgNotRegistered = &RpcError{errCode: CommErr, errStr: "rpc message not registered !"}
)
type RpcError struct {
errCode RpcErrorCode
errStr string
}
func (re *RpcError) Error() string {
return re.errStr
}
func (re *RpcError) Code() RpcErrorCode {
return re.errCode
}
func NewRpcError(code RpcErrorCode, format string, args ...interface{}) *RpcError {
return &RpcError{
errCode: code,
errStr: fmt.Sprintf(format, args...),
}
}
func NewProxyNotExit(proxyid uint32) *RpcError {
return &RpcError{
ProxyNotExist,
fmt.Sprintf("Proxy %d Not Exist", proxyid),
}
}
func NewProxyDisconnected(uuid uint64, id uint32, name string) *RpcError {
return &RpcError{
ProxyDisconnected,
fmt.Sprintf("%s's proxy uuid:%d id:%d has been disconnected", name, uuid, id),
}
}
func NewMethodExecError(service, method string) *RpcError {
return &RpcError{
MethodException,
fmt.Sprintf("%s::%s execute error !", service, method),
}
}
func NewServiceNotExist(uuid uint64) *RpcError {
return &RpcError{
ServiceNotExist,
fmt.Sprintf("service %d not exist", uuid),
}
}
func NewProxyNotFound(callid uint32) *RpcError {
return &RpcError{
ProxyCallNoFound,
fmt.Sprintf("proxy call %d not exits", callid),
}
}
type RpcPanicInfo struct {
Info interface{}
Pkg []byte
}
func (info RpcPanicInfo) String() string {
return fmt.Sprintf("RPC CALL PANIC: %v", info.Info)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dennis-kk/rpc-go-backend.git
git@gitee.com:dennis-kk/rpc-go-backend.git
dennis-kk
rpc-go-backend
rpc-go-backend
v0.5.10

搜索帮助

344bd9b3 5694891 D2dac590 5694891