-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy patherrors.go
77 lines (60 loc) · 1.53 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
// SPDX-FileCopyrightText: 2021 The Go-SSB Authors
//
// SPDX-License-Identifier: MIT
package ssb
import (
"encoding/json"
"errors"
"fmt"
refs "github.com/ssbc/go-ssb-refs"
)
var ErrShuttingDown = fmt.Errorf("ssb: shutting down now") // this is fine
type ErrOutOfReach struct {
Dist int
Max int
}
func (e ErrOutOfReach) Error() string {
return fmt.Sprintf("ssb/graph: peer not in reach. d:%d, max:%d", e.Dist, e.Max)
}
func IsMessageUnusable(err error) bool {
if errors.Is(err, ErrWrongType{}) {
return true
}
if errors.Is(err, ErrMalfromedMsg{}) {
return true
}
if errors.Is(err, &json.SyntaxError{}) {
return true
}
return false
}
type ErrMalfromedMsg struct {
reason string
m map[string]interface{}
}
func (emm ErrMalfromedMsg) Error() string {
s := "ErrMalfromedMsg: " + emm.reason
if emm.m != nil {
s += fmt.Sprintf(" %+v", emm.m)
}
return s
}
type ErrWrongType struct {
has, want string
}
func (ewt ErrWrongType) Error() string {
return fmt.Sprintf("ErrWrongType: want: %s has: %s", ewt.want, ewt.has)
}
var ErrUnuspportedFormat = fmt.Errorf("ssb: unsupported format")
// ErrWrongSequence is returned if there is a glitch on the current
// sequence number on the feed between in the offsetlog and the logical entry on the feed
type ErrWrongSequence struct {
Ref refs.FeedRef
Logical, Stored int64
}
func (e ErrWrongSequence) Error() string {
return fmt.Sprintf("ssb/consistency error: message sequence missmatch for feed %s Stored:%d Logical:%d",
e.Ref.String(),
e.Stored,
e.Logical)
}