forked from keybase/client
/
errors.go
110 lines (85 loc) · 1.89 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
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()
}