go.uber.org/yarpc@v1.72.1/api/peer/errors.go (about) 1 // Copyright (c) 2022 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package peer 22 23 import "fmt" 24 25 // ErrPeerHasNoReferenceToSubscriber is called when a Peer is expected 26 // to operate on a PeerSubscriber it has no reference to 27 type ErrPeerHasNoReferenceToSubscriber struct { 28 PeerIdentifier Identifier 29 PeerSubscriber Subscriber 30 } 31 32 func (e ErrPeerHasNoReferenceToSubscriber) Error() string { 33 return fmt.Sprintf("peer (%v) has no reference to peer subscriber (%v)", e.PeerIdentifier, e.PeerSubscriber) 34 } 35 36 // ErrTransportHasNoReferenceToPeer is called when a transport is expected to 37 // operate on a Peer it has no reference to 38 type ErrTransportHasNoReferenceToPeer struct { 39 TransportName string 40 PeerIdentifier string 41 } 42 43 func (e ErrTransportHasNoReferenceToPeer) Error() string { 44 return fmt.Sprintf("transport %q has no reference to peer %q", e.TransportName, e.PeerIdentifier) 45 } 46 47 // ErrInvalidPeerType is when a specfic peer type is required, but 48 // was not passed in 49 type ErrInvalidPeerType struct { 50 ExpectedType string 51 PeerIdentifier Identifier 52 } 53 54 func (e ErrInvalidPeerType) Error() string { 55 return fmt.Sprintf("expected peer type (%s) but got peer (%v)", e.ExpectedType, e.PeerIdentifier) 56 } 57 58 // ErrPeerListAlreadyStarted represents a failure because Start() was already 59 // called on the peerlist. 60 type ErrPeerListAlreadyStarted string 61 62 func (e ErrPeerListAlreadyStarted) Error() string { 63 return fmt.Sprintf("%s has already been started", string(e)) 64 } 65 66 // ErrPeerListNotStarted represents a failure because Start() was not called 67 // on a peerlist or if Stop() was called. 68 type ErrPeerListNotStarted string 69 70 func (e ErrPeerListNotStarted) Error() string { 71 return fmt.Sprintf("%s has not been started or was stopped", string(e)) 72 } 73 74 // ErrInvalidPeerConversion is called when a peer can't be properly converted 75 type ErrInvalidPeerConversion struct { 76 Peer Peer 77 ExpectedType string 78 } 79 80 func (e ErrInvalidPeerConversion) Error() string { 81 return fmt.Sprintf("cannot convert peer (%v) to type %s", e.Peer, e.ExpectedType) 82 } 83 84 // ErrInvalidTransportConversion is called when a transport can't be properly converted 85 type ErrInvalidTransportConversion struct { 86 Transport Transport 87 ExpectedType string 88 } 89 90 func (e ErrInvalidTransportConversion) Error() string { 91 return fmt.Sprintf("cannot convert transport (%v) to type %s", e.Transport, e.ExpectedType) 92 } 93 94 // ErrPeerAddAlreadyInList is returned to peer list updater if the 95 // peerlist is already tracking a peer for the added identifier 96 type ErrPeerAddAlreadyInList string 97 98 func (e ErrPeerAddAlreadyInList) Error() string { 99 return fmt.Sprintf("can't add peer %q because is already in peerlist", string(e)) 100 } 101 102 // ErrPeerRemoveNotInList is returned to peer list updater if the peerlist 103 // is not tracking the peer to remove for a given identifier 104 type ErrPeerRemoveNotInList string 105 106 func (e ErrPeerRemoveNotInList) Error() string { 107 return fmt.Sprintf("can't remove peer (%s) because it is not in peerlist", string(e)) 108 } 109 110 // ErrChooseContextHasNoDeadline is returned when a context is sent to a peerlist with no deadline 111 // DEPRECATED use yarpcerrors api instead. 112 type ErrChooseContextHasNoDeadline string 113 114 func (e ErrChooseContextHasNoDeadline) Error() string { 115 return fmt.Sprintf("can't wait for peer without a context deadline for peerlist %q", string(e)) 116 }