This repository has been archived by the owner on Jul 7, 2020. It is now read-only.
forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
138 lines (107 loc) · 2.34 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
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
package storage
import (
"context"
"fmt"
"github.com/keybase/client/go/chat/utils"
"github.com/keybase/client/go/protocol/chat1"
)
type Error interface {
error
ShouldClear() bool
Message() string
}
type InternalError struct {
Msg string
}
func (e InternalError) ShouldClear() bool {
return true
}
func (e InternalError) Error() string {
return fmt.Sprintf("internal chat storage error: %s", e.Msg)
}
func (e InternalError) Message() string {
return e.Msg
}
func NewInternalError(ctx context.Context, d utils.DebugLabeler, msg string, args ...interface{}) InternalError {
d.Debug(ctx, "internal chat storage error: "+msg, args...)
return InternalError{Msg: fmt.Sprintf(msg, args...)}
}
type MissError struct {
Msg string
}
func (e MissError) Error() string {
if len(e.Msg) > 0 {
return "chat cache miss: " + e.Msg
}
return "chat cache miss"
}
func (e MissError) ShouldClear() bool {
return false
}
func (e MissError) Message() string {
return e.Error()
}
type RemoteError struct {
Msg string
}
func (e RemoteError) Error() string {
return fmt.Sprintf("chat remote error: %s", e.Msg)
}
func (e RemoteError) ShouldClear() bool {
return false
}
func (e RemoteError) Message() string {
return e.Msg
}
type MiscError struct {
Msg string
}
func (e MiscError) Error() string {
return e.Msg
}
func (e MiscError) ShouldClear() bool {
return false
}
func (e MiscError) Message() string {
return e.Msg
}
type VersionMismatchError struct {
old, new chat1.InboxVers
}
func NewVersionMismatchError(oldVers chat1.InboxVers, newVers chat1.InboxVers) VersionMismatchError {
return VersionMismatchError{
old: oldVers,
new: newVers,
}
}
func (e VersionMismatchError) Error() string {
return fmt.Sprintf("version mismatch error: old %d new: %d", e.old, e.new)
}
func (e VersionMismatchError) ShouldClear() bool {
return false
}
func (e VersionMismatchError) Message() string {
return e.Error()
}
type AbortedError struct{}
func NewAbortedError() AbortedError {
return AbortedError{}
}
func (e AbortedError) Error() string {
return "request aborted"
}
func (e AbortedError) ShouldClear() bool {
return false
}
func (e AbortedError) Message() string {
return e.Error()
}
func isAbortedRequest(ctx context.Context) Error {
// Check context for aborted request
select {
case <-ctx.Done():
return NewAbortedError()
default:
}
return nil
}