-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
224 lines (175 loc) · 4.95 KB
/
error.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package db
import "fmt"
// ErrWriteUnexpectedBytes is error if write to file returns an unexpected amount of bytes
type ErrWriteUnexpectedBytes struct {
file string
}
// newErrWriteUnexpectedBytes creates new ErrWriteUnexpectedBytes with specified file
func newErrWriteUnexpectedBytes(file string) *ErrWriteUnexpectedBytes {
return &ErrWriteUnexpectedBytes{file: file}
}
func (e *ErrWriteUnexpectedBytes) Error() string {
return "Wrote unexpected amount of bytes to " + e.file
}
type ErrReadUnexpectedBytes struct {
file string
}
func newErrReadUnexpectedBytes(file string) *ErrReadUnexpectedBytes {
return &ErrReadUnexpectedBytes{file: file}
}
func (e *ErrReadUnexpectedBytes) Error() string {
return "Read unexpected amount of bytes from " + e.file
}
type ErrKeyNotFound struct{}
func newErrKeyNotFound() *ErrKeyNotFound {
return &ErrKeyNotFound{}
}
func (e *ErrKeyNotFound) Error() string {
return "Key not found"
}
type ErrIncorrectBlockSize struct{}
func newErrIncorrectBlockSize() *ErrIncorrectBlockSize {
return &ErrIncorrectBlockSize{}
}
func (e *ErrIncorrectBlockSize) Error() string {
return "Data block does not match block size"
}
type ErrIncorrectValueSize struct {
valueType uint8
valueSize int
}
func newErrIncorrectValueSize(valueType uint8, valueSize int) *ErrIncorrectValueSize {
return &ErrIncorrectValueSize{
valueType: valueType,
valueSize: valueSize,
}
}
func (e *ErrIncorrectValueSize) Error() string {
valueType := ""
switch e.valueType {
case Bool:
valueType = "Bool"
case Int:
valueType = "Int"
case Float:
valueType = "Float"
case String:
valueType = "String"
case Bytes:
valueType = "Bytes"
case Tombstone:
valueType = "Tombstone"
}
return fmt.Sprintf("Value byte size %d is not appropriate for %s", e.valueSize, valueType)
}
type ErrIncompatibleValue struct {
valueType uint8
}
func newErrIncompatibleValue(valueType uint8) *ErrIncompatibleValue {
return &ErrIncompatibleValue{
valueType: valueType,
}
}
func (e *ErrIncompatibleValue) Error() string {
valueType := ""
switch e.valueType {
case Bool:
valueType = "Bool"
case Int:
valueType = "Int"
case Float:
valueType = "Float"
case String:
valueType = "String"
case Bytes:
valueType = "Bytes"
case Tombstone:
valueType = "Tombstone"
}
return fmt.Sprintf("Incompatible value bytes for %s", valueType)
}
type ErrNoTypeFound struct{}
func newErrNoTypeFound() *ErrNoTypeFound {
return &ErrNoTypeFound{}
}
func (e *ErrNoTypeFound) Error() string {
return "No valid type found"
}
type ErrExceedMaxKeySize struct {
key string
}
func newErrExceedMaxKeySize(key string) *ErrExceedMaxKeySize {
return &ErrExceedMaxKeySize{key: key}
}
func (e *ErrExceedMaxKeySize) Error() string {
return fmt.Sprintf("Key: %v has length %d, which exceeds max key size %d", e.key, len(e.key), KeySize)
}
type ErrExceedMaxValueSize struct{}
func newErrExceedMaxValueSize() *ErrExceedMaxValueSize {
return &ErrExceedMaxValueSize{}
}
func (e *ErrExceedMaxValueSize) Error() string {
return fmt.Sprintf("Value size has exceeded max value size: %d", EntrySize)
}
type ErrDuplicateKey struct {
key string
}
func newErrDuplicateKey(key string) *ErrDuplicateKey {
return &ErrDuplicateKey{key: key}
}
func (e *ErrDuplicateKey) Error() string {
return fmt.Sprintf("Primary key already exists: %v", e.key)
}
type ErrTxnAbort struct{}
func newErrTxnAbort() *ErrTxnAbort {
return &ErrTxnAbort{}
}
func (e *ErrTxnAbort) Error() string {
return fmt.Sprintf("Txn aborted due to concurrent writes to key(s) from other txns")
}
type ErrExceedMaxAttributes struct{}
func newErrExceedMaxAttributes() *ErrExceedMaxAttributes {
return &ErrExceedMaxAttributes{}
}
func (e *ErrExceedMaxAttributes) Error() string {
return fmt.Sprintf("Amount of Attributes in entry exceed maximum (%d) amount of Attributes", MaxAttributes)
}
type ErrExceedMaxEntrySize struct{}
func newErrExceedMaxEntrySize() *ErrExceedMaxEntrySize {
return &ErrExceedMaxEntrySize{}
}
func (e *ErrExceedMaxEntrySize) Error() string {
return fmt.Sprintf("Size of entry has exceeded maximum size of %d bytes", EntrySize)
}
type ErrDecodeEntry struct{}
func newErrDecodeEntry() *ErrDecodeEntry {
return &ErrDecodeEntry{}
}
func (e *ErrDecodeEntry) Error() string {
return fmt.Sprintf("Error decoding entry from file")
}
type ErrBadFormattedSST struct{}
func newErrBadFormattedSST() *ErrBadFormattedSST {
return &ErrBadFormattedSST{}
}
func (e *ErrBadFormattedSST) Error() string {
return fmt.Sprintf("Bad formatted SST File")
}
type ErrParseValue struct {
value *Value
}
func newErrParseValue(value *Value) *ErrParseValue {
return &ErrParseValue{value: value}
}
func (e *ErrParseValue) Error() string {
return fmt.Sprintf("Error parsing value in entry: %v", e.value)
}
type ErrKeyAlreadyExists struct {
key string
}
func newErrKeyAlreadyExists(key string) *ErrKeyAlreadyExists {
return &ErrKeyAlreadyExists{key: key}
}
func (e *ErrKeyAlreadyExists) Error() string {
return fmt.Sprintf("Key: %v already exists in the DB", e.key)
}