-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
135 lines (127 loc) · 2.48 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
package petrel
// Copyright (c) 2014-2022 Shawn Boyette <[email protected]>. All
// rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import (
"fmt"
)
// Message levels control which messages will be sent to h.Msgr
const (
Debug = iota
Conn
Error
Fatal
)
var (
// Errs is the map of Perr instances. It is used by Msg
// handling code throughout the Petrel packages.
Errs = map[string]*Perr{
"connect": {
100,
Conn,
"client connected",
nil},
"dispatch": {
101,
Debug,
"dispatching",
nil},
"netreaderr": {
196,
Conn,
"network read error",
nil},
"netwriteerr": {
197,
Conn,
"network write error",
nil},
"disconnect": {
198,
Conn,
"client disconnected",
nil},
"quit": {
199,
Debug,
"Quit called: closing listener socket",
nil},
"success": {
200,
Debug,
"reply sent",
nil},
"badreq": {
400,
Debug,
"bad command",
[]byte("PERRPERR400")},
"nilreq": {
401,
Debug,
"nil request",
[]byte("PERRPERR401")},
"plenex": {
402,
Error,
"payload length limit exceeded; closing conn",
[]byte("PERRPERR402")},
"reqerr": {
500,
Error,
"request failed",
[]byte("PERRPERR500")},
"internalerr": {
501,
Error,
"internal error",
nil},
"badmac": {
502,
Error,
"HMAC verification failed; closing conn",
[]byte("PERRPERR502")},
"listenerfail": {
599,
Fatal,
"read from listener socket failed",
nil},
}
// Errmap lets you go the other way, from a numeric status to
// the name of a Perr
Errmap = map[int]string{
100: "connect",
101: "dispatch",
196: "netreaderr",
197: "netwriteerr",
198: "disconnect",
199: "quit",
200: "success",
400: "badreq",
401: "nilreq",
402: "plenex",
403: "badmac",
500: "reqerr",
501: "internalerr",
599: "listenerfail"}
// Loglvl maps string logging levels (from configurations) to
// their int equivalents (actually used in code)
Loglvl = map[string]int{
"debug": Debug,
"conn": Conn,
"error": Error,
"fatal": Fatal}
)
// Perr is a Petrel error -- though perhaps a better name would have
// been Pstatus. The data which is used to generate internal and
// external informational and error messages are stored as Perrs.
type Perr struct {
Code int
Lvl int
Txt string
Xmit []byte
}
// Error implements the error interface for Perr.
func (p Perr) Error() string {
return fmt.Sprintf("%s (%d)", p.Txt, p.Code)
}