github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/merkletree2/errors.go (about) 1 package merkletree2 2 3 import "fmt" 4 5 // InvalidConfigError happens when trying to construct an invalid tree configuration. 6 type InvalidConfigError struct { 7 reason string 8 } 9 10 func (e InvalidConfigError) Error() string { 11 return fmt.Sprintf("Invalid Config Error: %s", e.reason) 12 } 13 14 // NewInvalidConfigError returns a new error 15 func NewInvalidConfigError(reason string) InvalidConfigError { 16 return InvalidConfigError{reason: reason} 17 } 18 19 // InvalidKeyError is returned when trying to use a key of the wrong length in a tree. 20 type InvalidKeyError struct{} 21 22 func (e InvalidKeyError) Error() string { 23 return "Invalid Key (has the wrong length)." 24 } 25 26 // NewInvalidKeyError returns a new error 27 func NewInvalidKeyError() InvalidKeyError { 28 return InvalidKeyError{} 29 } 30 31 // ProofVerificationFailedError is returned when a merkle tree proof verification fails. 32 type ProofVerificationFailedError struct { 33 reason error 34 } 35 36 func (e ProofVerificationFailedError) Error() string { 37 return fmt.Sprintf("Proof Verification Error: %s", e.reason) 38 } 39 40 // NewProofVerificationFailedError returns a new error 41 func NewProofVerificationFailedError(reason error) ProofVerificationFailedError { 42 return ProofVerificationFailedError{reason: reason} 43 } 44 45 // NodeNotFoundError is returned by a StorageEngine when trying to fetch an internal node 46 // which is not part of the tree at a specific Seqno. 47 type NodeNotFoundError struct{} 48 49 func (e NodeNotFoundError) Error() string { 50 return "Node not found." 51 } 52 53 // NewNodeNotFoundError returns a new error 54 func NewNodeNotFoundError() NodeNotFoundError { 55 return NodeNotFoundError{} 56 } 57 58 // KeyNotFoundError is returned when trying to fetch a key which is not part of 59 // the tree at a specific Seqno. 60 type KeyNotFoundError struct{} 61 62 func (e KeyNotFoundError) Error() string { 63 return "Key not found." 64 } 65 66 // NewKeyNotFoundError returns a new error 67 func NewKeyNotFoundError() KeyNotFoundError { 68 return KeyNotFoundError{} 69 } 70 71 // NoLatestRootFoundError is returned when trying to fetch the latest root from 72 // an empty tree. 73 type NoLatestRootFoundError struct{} 74 75 func (e NoLatestRootFoundError) Error() string { 76 return "No latest root was found." 77 } 78 79 // NewNoLatestRootFoundError returns a new error 80 func NewNoLatestRootFoundError() NoLatestRootFoundError { 81 return NoLatestRootFoundError{} 82 } 83 84 // InvalidSeqnoError is returned when trying to lookup a record with an invalid 85 // Seqno 86 type InvalidSeqnoError struct { 87 s Seqno 88 reason error 89 } 90 91 func (e InvalidSeqnoError) Error() string { 92 return fmt.Sprintf("Invalid Seqno Error (Seqno: %v): %s", e.s, e.reason) 93 } 94 95 // NewInvalidConfigError returns a new error 96 func NewInvalidSeqnoError(s Seqno, reason error) InvalidSeqnoError { 97 return InvalidSeqnoError{s: s, reason: reason} 98 }