This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
error.go
109 lines (86 loc) · 2.59 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
package storage
import (
"errors"
"fmt"
"github.com/Worldcoin/hubble-commander/models"
"github.com/Worldcoin/hubble-commander/utils"
)
var (
ErrNoRowsAffected = fmt.Errorf("no rows were affected by the update")
ErrNonexistentState = fmt.Errorf("cannot revert to nonexistent state")
ErrAlreadyMinedTransaction = fmt.Errorf("transaction already mined")
AnyNotFoundError, anyNotFoundErrorSupport = utils.NewAnyError(&NotFoundError{})
)
type NotFoundError struct {
*utils.AnyErrorSupport
field string
}
func NewNotFoundError(field string) *NotFoundError {
return &NotFoundError{
AnyErrorSupport: anyNotFoundErrorSupport,
field: field,
}
}
func (e *NotFoundError) Unwrap() error {
return e.AnyErrorSupport
}
func (e *NotFoundError) Error() string {
return fmt.Sprintf("%s not found", e.field)
}
func (e *NotFoundError) Is(other error) bool {
otherError, ok := other.(*NotFoundError)
if !ok {
return false
}
return *e == *otherError
}
func IsNotFoundError(err error) bool {
if err == nil {
return false
}
target := &NotFoundError{}
return errors.As(err, &target)
}
type InvalidPubKeyIDError struct {
value uint32
}
func NewInvalidPubKeyIDError(value uint32) *InvalidPubKeyIDError {
return &InvalidPubKeyIDError{value: value}
}
func (e *InvalidPubKeyIDError) Error() string {
return fmt.Sprintf("invalid pubKeyID value: %d", e.value)
}
type AccountAlreadyExistsError struct {
Account *models.AccountLeaf
}
func NewAccountAlreadyExistsError(account *models.AccountLeaf) *AccountAlreadyExistsError {
return &AccountAlreadyExistsError{Account: account}
}
func (e *AccountAlreadyExistsError) Error() string {
return fmt.Sprintf("account with pubKeyID %d already exists", e.Account.PubKeyID)
}
type AccountBatchAlreadyExistsError struct {
Accounts []models.AccountLeaf
}
func NewAccountBatchAlreadyExistsError(accounts []models.AccountLeaf) *AccountBatchAlreadyExistsError {
return &AccountBatchAlreadyExistsError{Accounts: accounts}
}
func (e *AccountBatchAlreadyExistsError) Error() string {
return fmt.Sprintf("accounts with pubKeyIDs %v already exist", e.Accounts)
}
type NoVacantSubtreeError struct {
subtreeDepth uint8
}
func NewNoVacantSubtreeError(subtreeDepth uint8) *NoVacantSubtreeError {
return &NoVacantSubtreeError{subtreeDepth: subtreeDepth}
}
func (e *NoVacantSubtreeError) Error() string {
return fmt.Sprintf("no vacant slot found in the State Tree for a subtree of depth %d", e.subtreeDepth)
}
func (e *NoVacantSubtreeError) Is(other error) bool {
otherError, ok := other.(*NoVacantSubtreeError)
if !ok {
return false
}
return *e == *otherError
}