/
getNodeFromDBErrWithKey.go
50 lines (42 loc) · 1.28 KB
/
getNodeFromDBErrWithKey.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
package core
import (
"encoding/hex"
"fmt"
)
// GetNodeFromDBErrorString represents the string which is returned when a getting node from DB returns an error
const GetNodeFromDBErrorString = "getNodeFromDB error"
// getNodeFromDBErrWithKey defines a custom error for trie get node
type getNodeFromDBErrWithKey struct {
getErr error
key []byte
dbIdentifier string
}
// NewGetNodeFromDBErrWithKey will create a new instance of GetNodeFromDBErrWithKey
func NewGetNodeFromDBErrWithKey(key []byte, err error, id string) *getNodeFromDBErrWithKey {
return &getNodeFromDBErrWithKey{
getErr: err,
key: key,
dbIdentifier: id,
}
}
// Error returns the error as string
func (e *getNodeFromDBErrWithKey) Error() string {
return fmt.Sprintf(
"%s: %s for key %v",
GetNodeFromDBErrorString,
e.getErr.Error(),
hex.EncodeToString(e.key),
)
}
// GetKey will return the key that generated the error
func (e *getNodeFromDBErrWithKey) GetKey() []byte {
return e.key
}
// GetIdentifier will return the db identifier corresponding to the db
func (e *getNodeFromDBErrWithKey) GetIdentifier() string {
return e.dbIdentifier
}
// IsInterfaceNil returns true if there is no value under the interface
func (e *getNodeFromDBErrWithKey) IsInterfaceNil() bool {
return e == nil
}