-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy patherror.go
102 lines (80 loc) · 3.25 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2020 The Cockroach Authors.
//
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
package sqlproxyccl
import (
"fmt"
"github.com/cockroachdb/errors"
)
// errorCode classifies errors emitted by Proxy().
//go:generate stringer -type=errorCode
type errorCode int
const (
_ errorCode = iota
// codeAuthFailed indicates that client authentication attempt has failed and
// backend has closed the connection.
codeAuthFailed
// codeBackendReadFailed indicates an error reading from backend connection.
codeBackendReadFailed
// codeBackendWriteFailed indicates an error writing to backend connection.
codeBackendWriteFailed
// codeClientReadFailed indicates an error reading from the client connection
codeClientReadFailed
// codeClientWriteFailed indicates an error writing to the client connection.
codeClientWriteFailed
// codeUnexpectedInsecureStartupMessage indicates that the client sent a
// StartupMessage which was unexpected. Typically this means that an
// SSLRequest was expected but the client attempted to go ahead without TLS,
// or vice versa.
codeUnexpectedInsecureStartupMessage
// codeSNIRoutingFailed indicates an error choosing a backend address based on
// the client's SNI header.
codeSNIRoutingFailed
// codeUnexpectedStartupMessage indicates an unexpected startup message
// received from the client after TLS negotiation.
codeUnexpectedStartupMessage
// codeParamsRoutingFailed indicates an error choosing a backend address based
// on the client's session parameters.
codeParamsRoutingFailed
// codeBackendDown indicates an error establishing or maintaining a connection
// to the backend SQL server.
codeBackendDown
// codeBackendRefusedTLS indicates that the backend SQL server refused a TLS-
// enabled SQL connection.
codeBackendRefusedTLS
// codeBackendDisconnected indicates that the backend disconnected (with a
// connection error) while serving client traffic.
codeBackendDisconnected
// codeClientDisconnected indicates that the client disconnected unexpectedly
// (with a connection error) while in a session with backend SQL server.
codeClientDisconnected
// codeProxyRefusedConnection indicates that the proxy refused the connection
// request due to high load or too many connection attempts.
codeProxyRefusedConnection
// codeExpiredClientConnection indicates that proxy connection to the client
// has expired and should be closed.
codeExpiredClientConnection
// codeIdleDisconnect indicates that the connection was disconnected for
// being idle for longer than the specified timeout.
codeIdleDisconnect
)
// codeError is combines an error with one of the above codes to ease
// the processing of the errors.
type codeError struct {
code errorCode
err error
}
func (e *codeError) Error() string {
return fmt.Sprintf("%s: %s", e.code, e.err)
}
// newErrorf returns a new codeError out of the supplied args.
func newErrorf(code errorCode, format string, args ...interface{}) error {
return &codeError{
code: code,
err: errors.Errorf(format, args...),
}
}