forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
proto3.go
39 lines (33 loc) · 1.04 KB
/
proto3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vterrors
import (
"errors"
vtrpcpb "github.com/youtube/vitess/go/vt/proto/vtrpc"
)
// This file contains the necessary methods to send and receive errors
// as payloads of proto3 structures. It converts VitessError to and from
// vtrpcpb.Error. Use these methods when a RPC call can return both
// data and an error.
// FromVtRPCError recovers a VitessError from a *vtrpcpb.RPCError (which is how VitessErrors
// are transmitted across proto3 RPC boundaries).
func FromVtRPCError(rpcErr *vtrpcpb.RPCError) error {
if rpcErr == nil {
return nil
}
return &VitessError{
Code: rpcErr.Code,
err: errors.New(rpcErr.Message),
}
}
// VtRPCErrorFromVtError converts from a VtError to a vtrpcpb.RPCError.
func VtRPCErrorFromVtError(err error) *vtrpcpb.RPCError {
if err == nil {
return nil
}
return &vtrpcpb.RPCError{
Code: RecoverVtErrorCode(err),
Message: err.Error(),
}
}