-
Notifications
You must be signed in to change notification settings - Fork 97
/
err.go
38 lines (33 loc) · 1.05 KB
/
err.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
package minecraft
import (
"errors"
"net"
)
var (
// TODO: Change this to net.ErrClosed in 1.16.
errClosed = errors.New("use of closed network connection")
errBufferTooSmall = errors.New("a message sent was larger than the buffer used to receive the message into")
errListenerClosed = errors.New("use of closed listener")
)
// wrap wraps the error passed into a net.OpError with the op as operation and returns it, or nil if the error
// passed is nil.
func (conn *Conn) wrap(err error, op string) error {
if err == nil {
return nil
}
return &net.OpError{
Op: op,
Net: "minecraft",
Source: conn.LocalAddr(),
Addr: conn.RemoteAddr(),
Err: err,
}
}
// DisconnectError is an error returned by operations from Conn when the connection is closed by the other
// end through a packet.Disconnect. It is wrapped in a net.OpError and may be obtained using
// errors.Unwrap(net.OpError).
type DisconnectError string
// Error returns the message held in the packet.Disconnect.
func (d DisconnectError) Error() string {
return string(d)
}