-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
105 lines (90 loc) · 2.27 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
package minq
import (
"fmt"
)
// Errors which don't necesarily cause connection teardown.
type intError struct {
err string
sub string
fatal bool
}
func (e intError) Error() string {
return e.err
}
func fatalError(format string, args ...interface{}) error {
return intError{
fmt.Sprintf(format, args...),
"",
true,
}
}
func internalError(format string, args ...interface{}) error {
str := fmt.Sprintf(format, args...)
if debug {
panic("Internal error: " + str)
}
return intError{
str,
"",
true,
}
}
func nonFatalError(format string, args ...interface{}) error {
return intError{
fmt.Sprintf(format, args...),
"",
false,
}
}
func err2string(err interface{}) string {
switch e := err.(type) {
case error:
return e.Error()
case string:
return e
default:
panic("Bogus argument to err2string")
}
}
func wrapE(err interface{}, sub interface{}) error {
return intError{
err2string(err),
err2string(sub),
isFatalError(err),
}
}
// An error is fatal if either.
//
// It's a regular error (i.e., not an intError)
// e.fatal is true
func isFatalError(e interface{}) bool {
if e == nil {
return false
}
i, ok := e.(intError)
if !ok {
return true
}
return i.fatal
}
// Return codes.
var ErrorWouldBlock = nonFatalError("Would have blocked (QUIC)")
var ErrorDestroyConnection = fatalError("Terminate connection")
var ErrorReceivedVersionNegotiation = fatalError("Received a version negotiation packet advertising a different version than ours")
var ErrorConnIsClosed = fatalError("Connection is closed")
var ErrorConnIsClosing = nonFatalError("Connection is closing")
var ErrorStreamReset = fatalError("Stream was reset")
var ErrorStreamIsClosed = fatalError("Stream is closed")
var ErrorInvalidPacket = nonFatalError("Invalid packet")
var ErrorConnectionTimedOut = fatalError("Connection timed out")
var ErrorMissingValue = fatalError("Expected value is missing")
var ErrorInvalidEncoding = fatalError("Invalid encoding")
var ErrorProtocolViolation = fatalError("Protocol violation")
var ErrorFrameFormatError = fatalError("Frame format error")
var ErrorFlowControlError = fatalError("Flow control error")
// Protocol errors
type ErrorCode uint16
const (
kQuicErrorNoError = ErrorCode(0x0000)
kQuicErrorProtocolViolation = ErrorCode(0x000A)
)