-
Notifications
You must be signed in to change notification settings - Fork 502
/
error.go
121 lines (99 loc) · 2.67 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package mssql
import (
"database/sql/driver"
"fmt"
)
// Error represents an SQL Server error. This
// type includes methods for reading the contents
// of the struct, which allows calling programs
// to check for specific error conditions without
// having to import this package directly.
type Error struct {
Number int32
State uint8
Class uint8
Message string
ServerName string
ProcName string
LineNo int32
// All lists all errors that were received from first to last.
// This includes the last one, which is described in the other members.
All []Error
}
func (e Error) Error() string {
return "mssql: " + e.Message
}
func (e Error) String() string {
return e.Message
}
// SQLErrorNumber returns the SQL Server error number.
func (e Error) SQLErrorNumber() int32 {
return e.Number
}
func (e Error) SQLErrorState() uint8 {
return e.State
}
func (e Error) SQLErrorClass() uint8 {
return e.Class
}
func (e Error) SQLErrorMessage() string {
return e.Message
}
func (e Error) SQLErrorServerName() string {
return e.ServerName
}
func (e Error) SQLErrorProcName() string {
return e.ProcName
}
func (e Error) SQLErrorLineNo() int32 {
return e.LineNo
}
type StreamError struct {
InnerError error
}
func (e StreamError) Error() string {
return "Invalid TDS stream: " + e.InnerError.Error()
}
func badStreamPanic(err error) {
panic(StreamError{InnerError: err})
}
func badStreamPanicf(format string, v ...interface{}) {
panic(fmt.Errorf(format, v...))
}
// ServerError is returned when the server got a fatal error
// that aborts the process and severs the connection.
//
// To get the errors returned before the process was aborted,
// unwrap this error or call errors.As with a pointer to an
// mssql.Error variable.
type ServerError struct {
sqlError Error
}
func (e ServerError) Error() string {
return "SQL Server had internal error"
}
func (e ServerError) Unwrap() error {
return e.sqlError
}
// RetryableError is returned when an error was caused by a bad
// connection at the start of a query and can be safely retried
// using database/sql's automatic retry logic.
//
// In many cases database/sql's retry logic will transparently
// handle this error, the retried call will return successfully,
// and you won't even see this error. However, you may see this
// error if the retry logic cannot successfully handle the error.
// In that case you can get the underlying error by calling this
// error's UnWrap function.
type RetryableError struct {
err error
}
func (r RetryableError) Error() string {
return r.err.Error()
}
func (r RetryableError) Unwrap() error {
return r.err
}
func (r RetryableError) Is(err error) bool {
return err == driver.ErrBadConn
}