forked from libp2p/go-libp2p
/
error.go
81 lines (72 loc) · 2.36 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
package rcmgr
import (
"errors"
"github.com/chiangmaioneluv/go-libp2p/core/network"
)
type ErrStreamOrConnLimitExceeded struct {
current, attempted, limit int
err error
}
func (e *ErrStreamOrConnLimitExceeded) Error() string { return e.err.Error() }
func (e *ErrStreamOrConnLimitExceeded) Unwrap() error { return e.err }
// edge may be "" if this is not an edge error
func logValuesStreamLimit(scope, edge string, dir network.Direction, stat network.ScopeStat, err error) []interface{} {
logValues := make([]interface{}, 0, 2*8)
logValues = append(logValues, "scope", scope)
if edge != "" {
logValues = append(logValues, "edge", edge)
}
logValues = append(logValues, "direction", dir)
var e *ErrStreamOrConnLimitExceeded
if errors.As(err, &e) {
logValues = append(logValues,
"current", e.current,
"attempted", e.attempted,
"limit", e.limit,
)
}
return append(logValues, "stat", stat, "error", err)
}
// edge may be "" if this is not an edge error
func logValuesConnLimit(scope, edge string, dir network.Direction, usefd bool, stat network.ScopeStat, err error) []interface{} {
logValues := make([]interface{}, 0, 2*9)
logValues = append(logValues, "scope", scope)
if edge != "" {
logValues = append(logValues, "edge", edge)
}
logValues = append(logValues, "direction", dir, "usefd", usefd)
var e *ErrStreamOrConnLimitExceeded
if errors.As(err, &e) {
logValues = append(logValues,
"current", e.current,
"attempted", e.attempted,
"limit", e.limit,
)
}
return append(logValues, "stat", stat, "error", err)
}
type ErrMemoryLimitExceeded struct {
current, attempted, limit int64
priority uint8
err error
}
func (e *ErrMemoryLimitExceeded) Error() string { return e.err.Error() }
func (e *ErrMemoryLimitExceeded) Unwrap() error { return e.err }
// edge may be "" if this is not an edge error
func logValuesMemoryLimit(scope, edge string, stat network.ScopeStat, err error) []interface{} {
logValues := make([]interface{}, 0, 2*8)
logValues = append(logValues, "scope", scope)
if edge != "" {
logValues = append(logValues, "edge", edge)
}
var e *ErrMemoryLimitExceeded
if errors.As(err, &e) {
logValues = append(logValues,
"current", e.current,
"attempted", e.attempted,
"priority", e.priority,
"limit", e.limit,
)
}
return append(logValues, "stat", stat, "error", err)
}