-
Notifications
You must be signed in to change notification settings - Fork 12
/
errors.go
111 lines (88 loc) · 2.57 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
99
100
101
102
103
104
105
106
107
108
109
110
111
package client
import (
"errors"
"fmt"
"github.com/companyzero/bisonrelay/client/clientintf"
"github.com/companyzero/bisonrelay/zkidentity"
)
var (
errRemoteUserExiting = fmt.Errorf("remote user: %w", clientintf.ErrSubsysExiting)
errClientExiting = fmt.Errorf("client: %w", clientintf.ErrSubsysExiting)
errAlreadyExists = fmt.Errorf("already exists")
errUserBlocked = fmt.Errorf("user is blocked")
errRMTooLarge = errors.New("RM is too large")
errTimeoutWaitingHandlers = errors.New("timeout waiting for handlers to complete")
)
type userNotFoundError struct {
id string
}
func (err userNotFoundError) Error() string {
return fmt.Sprintf("user %s not found", err.id)
}
func (err userNotFoundError) Is(target error) bool {
_, ok := target.(userNotFoundError)
return ok
}
type alreadyHaveUserError struct {
id UserID
}
func (err alreadyHaveUserError) Error() string {
return fmt.Sprintf("already have user %s", err.id)
}
func (err alreadyHaveUserError) Is(target error) bool {
_, ok := target.(alreadyHaveUserError)
return ok
}
// WalletUsableErrorKind holds the types of errors that may happen when checking
// if an LN wallet is usable for payments to the server.
type WalletUsableErrorKind string
func (err WalletUsableErrorKind) Error() string {
return string(err)
}
// WalletUsableError is a complex error type that wraps both one the type of
// error and an underlying error (if it exists)
type WalletUsableError struct {
descr string
err error
}
func (err WalletUsableError) Error() string {
return err.descr
}
func (err WalletUsableError) Unwrap() error {
return err.err
}
func makeWalletUsableErr(kind WalletUsableErrorKind, descr string) WalletUsableError {
return WalletUsableError{descr: descr, err: kind}
}
// ErrKXSearchNeeded is returned when an action cannot be completed and a KX
// search must be performed.
type ErrKXSearchNeeded struct {
Author UserID
}
func (err ErrKXSearchNeeded) Error() string {
return fmt.Sprintf("KX search needed to find post author %s", err.Author)
}
func (err ErrKXSearchNeeded) Is(target error) bool {
if _, ok := target.(ErrKXSearchNeeded); ok {
return true
}
return false
}
type errHasOngoingKX struct {
otherRV zkidentity.ShortID
}
func (err errHasOngoingKX) Error() string {
return fmt.Sprintf("already has ongoing KX %s", err.otherRV)
}
func (err errHasOngoingKX) Is(target error) bool {
_, ok := target.(errHasOngoingKX)
return ok
}
func (err errHasOngoingKX) As(target interface{}) bool {
other, ok := target.(*errHasOngoingKX)
if !ok {
return false
}
other.otherRV = err.otherRV
return true
}