-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
errors.go
98 lines (76 loc) · 2.67 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
package merkletree2
import "fmt"
// InvalidConfigError happens when trying to construct an invalid tree configuration.
type InvalidConfigError struct {
reason string
}
func (e InvalidConfigError) Error() string {
return fmt.Sprintf("Invalid Config Error: %s", e.reason)
}
// NewInvalidConfigError returns a new error
func NewInvalidConfigError(reason string) InvalidConfigError {
return InvalidConfigError{reason: reason}
}
// InvalidKeyError is returned when trying to use a key of the wrong length in a tree.
type InvalidKeyError struct{}
func (e InvalidKeyError) Error() string {
return "Invalid Key (has the wrong length)."
}
// NewInvalidKeyError returns a new error
func NewInvalidKeyError() InvalidKeyError {
return InvalidKeyError{}
}
// ProofVerificationFailedError is returned when a merkle tree proof verification fails.
type ProofVerificationFailedError struct {
reason error
}
func (e ProofVerificationFailedError) Error() string {
return fmt.Sprintf("Proof Verification Error: %s", e.reason)
}
// NewProofVerificationFailedError returns a new error
func NewProofVerificationFailedError(reason error) ProofVerificationFailedError {
return ProofVerificationFailedError{reason: reason}
}
// NodeNotFoundError is returned by a StorageEngine when trying to fetch an internal node
// which is not part of the tree at a specific Seqno.
type NodeNotFoundError struct{}
func (e NodeNotFoundError) Error() string {
return "Node not found."
}
// NewNodeNotFoundError returns a new error
func NewNodeNotFoundError() NodeNotFoundError {
return NodeNotFoundError{}
}
// KeyNotFoundError is returned when trying to fetch a key which is not part of
// the tree at a specific Seqno.
type KeyNotFoundError struct{}
func (e KeyNotFoundError) Error() string {
return "Key not found."
}
// NewKeyNotFoundError returns a new error
func NewKeyNotFoundError() KeyNotFoundError {
return KeyNotFoundError{}
}
// NoLatestRootFoundError is returned when trying to fetch the latest root from
// an empty tree.
type NoLatestRootFoundError struct{}
func (e NoLatestRootFoundError) Error() string {
return "No latest root was found."
}
// NewNoLatestRootFoundError returns a new error
func NewNoLatestRootFoundError() NoLatestRootFoundError {
return NoLatestRootFoundError{}
}
// InvalidSeqnoError is returned when trying to lookup a record with an invalid
// Seqno
type InvalidSeqnoError struct {
s Seqno
reason error
}
func (e InvalidSeqnoError) Error() string {
return fmt.Sprintf("Invalid Seqno Error (Seqno: %v): %s", e.s, e.reason)
}
// NewInvalidConfigError returns a new error
func NewInvalidSeqnoError(s Seqno, reason error) InvalidSeqnoError {
return InvalidSeqnoError{s: s, reason: reason}
}