-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
77 lines (64 loc) · 1.86 KB
/
errors.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package cmd
import (
"fmt"
"sort"
"strings"
"github.com/jhump/protoreflect/desc"
)
var _ error = ChainNotFoundError{}
// ChainNotFoundError is used when a requested chain does not exist.
// Its error message includes the list of known chains.
type ChainNotFoundError struct {
Requested string
Config configService
}
func (e ChainNotFoundError) Error() string {
chainConfs := e.Config.clientConfig.GetChainConfigs()
available := make([]string, 0, len(chainConfs))
for chainName := range chainConfs {
available = append(available, chainName)
}
sort.Strings(available)
return fmt.Sprintf(
"no chain %q found (available chains: %s)",
e.Requested,
strings.Join(available, ", "),
)
}
var _ error = GRPCServiceNotFoundError{}
// GRPCServiceNotFoundError is used when a requested gRPC service does not exist.
// Its error message includes the provided available services.
type GRPCServiceNotFoundError struct {
Requested string
Available []string
}
func (e GRPCServiceNotFoundError) Error() string {
sort.Strings(e.Available)
// TODO: would be nice to suggest close matches here.
return fmt.Sprintf(
"no service %q found (available services: %s)",
e.Requested,
strings.Join(e.Available, ", "),
)
}
var _ error = GRPCMethodNotFoundError{}
// GRPCMethodNotFoundError is used when a requested gRPC method does not exist.
// Its error message includes the provided available services.
type GRPCMethodNotFoundError struct {
TargetService string
Requested string
Available []*desc.MethodDescriptor
}
func (e GRPCMethodNotFoundError) Error() string {
methodNames := make([]string, len(e.Available))
for i, md := range e.Available {
methodNames[i] = md.GetName()
}
sort.Strings(methodNames)
return fmt.Sprintf(
"service %q has no method with name %q (available methods: %s)",
e.TargetService,
e.Requested,
strings.Join(methodNames, ", "),
)
}