-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patherror.go
More file actions
93 lines (76 loc) · 2.43 KB
/
error.go
File metadata and controls
93 lines (76 loc) · 2.43 KB
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
package protocol
import (
"errors"
"fmt"
pb "friendnet.org/protocol/pb/v1"
)
var (
ErrCertStoreRequired = errors.New("cert store is required")
ErrProtocolVersionRequired = errors.New("protocol version is required")
ErrNoServerCerts = errors.New("no server certificates presented")
ErrServerCertNotValidNow = errors.New("server certificate is not valid at the current time")
)
// UnexpectedMsgTypeError is an error returned when expecting to receive a certain message type, but got another.
type UnexpectedMsgTypeError struct {
// The expected message type.
Expected pb.MsgType
// The actual message type received.
Actual pb.MsgType
}
func (e UnexpectedMsgTypeError) Error() string {
return fmt.Sprintf("expected message type %s but got type %s", e.Expected.String(), e.Actual.String())
}
func NewUnexpectedMsgTypeError(expected pb.MsgType, actual pb.MsgType) UnexpectedMsgTypeError {
return UnexpectedMsgTypeError{
Expected: expected,
Actual: actual,
}
}
// ProtoMsgError is an error returned when an error message is read from the protocol.
type ProtoMsgError struct {
Msg *pb.MsgError
}
func (e ProtoMsgError) Error() string {
var msg string
if e.Msg.Message != nil {
msg = ": " + *e.Msg.Message
}
return fmt.Sprintf(`received error message from protocol: %s%s`,
e.Msg.Type.String(),
msg,
)
}
func NewProtoMsgError(msg *pb.MsgError) ProtoMsgError {
return ProtoMsgError{
Msg: msg,
}
}
// CertMismatchError is returned when the server certificate changes for a host.
type CertMismatchError struct {
Host string
}
func (e CertMismatchError) Error() string {
return fmt.Sprintf("server certificate mismatch for %q", e.Host)
}
// VersionRejectedError is returned when the server rejects the client's protocol version.
type VersionRejectedError struct {
Reason pb.VersionRejectionReason
Message string
}
func (e VersionRejectedError) Error() string {
if e.Message == "" {
return fmt.Sprintf("protocol version rejected: %s", e.Reason.String())
}
return fmt.Sprintf("protocol version rejected: %s: %s", e.Reason.String(), e.Message)
}
// AuthRejectedError is returned when the server rejects authentication.
type AuthRejectedError struct {
Reason pb.AuthRejectionReason
Message string
}
func (e AuthRejectedError) Error() string {
if e.Message == "" {
return fmt.Sprintf("authentication rejected: %s", e.Reason.String())
}
return fmt.Sprintf("authentication rejected: %s: %s", e.Reason.String(), e.Message)
}