// FromRPCError recovers a VitessError from a *mproto.RPCError (which is how VitessErrors // are transmitted across RPC boundaries). func FromRPCError(rpcErr *mproto.RPCError) error { if rpcErr == nil { return nil } return &VitessError{ Code: vtrpc.ErrorCode(rpcErr.Code), err: fmt.Errorf("%v", rpcErr.Message), } }
// RPCErrorToVtRPCError converts a VTGate error into a vtrpc error. func RPCErrorToVtRPCError(rpcErr *mproto.RPCError) *vtrpc.RPCError { if rpcErr == nil { return nil } return &vtrpc.RPCError{ Code: vtrpc.ErrorCode(rpcErr.Code), Message: rpcErr.Message, } }
// TabletErrorToRPCError transforms the provided error to a RPCError, // if any. func TabletErrorToRPCError(err error) *vtrpc.RPCError { if err == nil { return nil } if terr, ok := err.(*TabletError); ok { return &vtrpc.RPCError{ // Transform TabletError code to VitessError code Code: vtrpc.ErrorCode(int64(terr.ErrorType) + vterrors.TabletError), // Make sure the the VitessError message is identical to the TabletError // err, so that downstream consumers will see identical messages no matter // which endpoint they're using. Message: terr.Error(), } } return &vtrpc.RPCError{ Code: vtrpc.ErrorCode_UnknownTabletError, Message: err.Error(), } }