/
errors.go
116 lines (94 loc) · 4.28 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2018 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package peer
import "fmt"
// ErrPeerHasNoReferenceToSubscriber is called when a Peer is expected
// to operate on a PeerSubscriber it has no reference to
type ErrPeerHasNoReferenceToSubscriber struct {
PeerIdentifier Identifier
PeerSubscriber Subscriber
}
func (e ErrPeerHasNoReferenceToSubscriber) Error() string {
return fmt.Sprintf("peer (%v) has no reference to peer subscriber (%v)", e.PeerIdentifier, e.PeerSubscriber)
}
// ErrTransportHasNoReferenceToPeer is called when a transport is expected to
// operate on a Peer it has no reference to
type ErrTransportHasNoReferenceToPeer struct {
TransportName string
PeerIdentifier string
}
func (e ErrTransportHasNoReferenceToPeer) Error() string {
return fmt.Sprintf("transport %q has no reference to peer %q", e.TransportName, e.PeerIdentifier)
}
// ErrInvalidPeerType is when a specfic peer type is required, but
// was not passed in
type ErrInvalidPeerType struct {
ExpectedType string
PeerIdentifier Identifier
}
func (e ErrInvalidPeerType) Error() string {
return fmt.Sprintf("expected peer type (%s) but got peer (%v)", e.ExpectedType, e.PeerIdentifier)
}
// ErrPeerListAlreadyStarted represents a failure because Start() was already
// called on the peerlist.
type ErrPeerListAlreadyStarted string
func (e ErrPeerListAlreadyStarted) Error() string {
return fmt.Sprintf("%s has already been started", string(e))
}
// ErrPeerListNotStarted represents a failure because Start() was not called
// on a peerlist or if Stop() was called.
type ErrPeerListNotStarted string
func (e ErrPeerListNotStarted) Error() string {
return fmt.Sprintf("%s has not been started or was stopped", string(e))
}
// ErrInvalidPeerConversion is called when a peer can't be properly converted
type ErrInvalidPeerConversion struct {
Peer Peer
ExpectedType string
}
func (e ErrInvalidPeerConversion) Error() string {
return fmt.Sprintf("cannot convert peer (%v) to type %s", e.Peer, e.ExpectedType)
}
// ErrInvalidTransportConversion is called when a transport can't be properly converted
type ErrInvalidTransportConversion struct {
Transport Transport
ExpectedType string
}
func (e ErrInvalidTransportConversion) Error() string {
return fmt.Sprintf("cannot convert transport (%v) to type %s", e.Transport, e.ExpectedType)
}
// ErrPeerAddAlreadyInList is returned to peer list updater if the
// peerlist is already tracking a peer for the added identifier
type ErrPeerAddAlreadyInList string
func (e ErrPeerAddAlreadyInList) Error() string {
return fmt.Sprintf("can't add peer %q because is already in peerlist", string(e))
}
// ErrPeerRemoveNotInList is returned to peer list updater if the peerlist
// is not tracking the peer to remove for a given identifier
type ErrPeerRemoveNotInList string
func (e ErrPeerRemoveNotInList) Error() string {
return fmt.Sprintf("can't remove peer (%s) because it is not in peerlist", string(e))
}
// ErrChooseContextHasNoDeadline is returned when a context is sent to a peerlist with no deadline
// DEPRECATED use yarpcerrors api instead.
type ErrChooseContextHasNoDeadline string
func (e ErrChooseContextHasNoDeadline) Error() string {
return fmt.Sprintf("can't wait for peer without a context deadline for peerlist %q", string(e))
}