forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
258 lines (227 loc) · 13.3 KB
/
errors.go
File metadata and controls
258 lines (227 loc) · 13.3 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package gosnowflake
import (
"fmt"
"runtime/debug"
"strconv"
"time"
sferrors "github.com/snowflakedb/gosnowflake/v2/internal/errors"
)
// SnowflakeError is a error type including various Snowflake specific information.
type SnowflakeError = sferrors.SnowflakeError
func generateTelemetryExceptionData(se *SnowflakeError) *telemetryData {
data := &telemetryData{
Message: map[string]string{
typeKey: sqlException,
sourceKey: telemetrySource,
driverTypeKey: "Go",
driverVersionKey: SnowflakeGoDriverVersion,
stacktraceKey: maskSecrets(string(debug.Stack())),
},
Timestamp: time.Now().UnixNano() / int64(time.Millisecond),
}
if se.QueryID != "" {
data.Message[queryIDKey] = se.QueryID
}
if se.SQLState != "" {
data.Message[sqlStateKey] = se.SQLState
}
if se.Message != "" {
data.Message[reasonKey] = se.Message
}
if len(se.MessageArgs) > 0 {
data.Message[reasonKey] = fmt.Sprintf(se.Message, se.MessageArgs...)
}
if se.Number != 0 {
data.Message[errorNumberKey] = strconv.Itoa(se.Number)
}
return data
}
// exceptionTelemetry generates telemetry data from the error and adds it to the telemetry queue.
func exceptionTelemetry(se *SnowflakeError, sc *snowflakeConn) *SnowflakeError {
if sc == nil || sc.telemetry == nil || !sc.telemetry.enabled {
return se // skip expensive stacktrace generation below if telemetry is disabled
}
data := generateTelemetryExceptionData(se)
if err := sc.telemetry.addLog(data); err != nil {
logger.WithContext(sc.ctx).Debugf("failed to log to telemetry: %v", data)
}
return se
}
// return populated error fields replacing the default response
func populateErrorFields(code int, data *execResponse) *SnowflakeError {
err := sferrors.ErrUnknownError()
if code != -1 {
err.Number = code
}
if data.Data.SQLState != "" {
err.SQLState = data.Data.SQLState
}
if data.Message != "" {
err.Message = data.Message
}
if data.Data.QueryID != "" {
err.QueryID = data.Data.QueryID
}
return err
}
// Snowflake Server Error code
const (
queryNotExecutingCode = "000605"
queryInProgressCode = "333333"
queryInProgressAsyncCode = "333334"
sessionExpiredCode = "390112"
invalidOAuthAccessTokenCode = "390303"
expiredOAuthAccessTokenCode = "390318"
)
// Driver return errors — re-exported from internal/errors
const (
/* connection */
// ErrCodeEmptyAccountCode is an error code for the case where a DSN doesn't include account parameter
ErrCodeEmptyAccountCode = sferrors.ErrCodeEmptyAccountCode
// ErrCodeEmptyUsernameCode is an error code for the case where a DSN doesn't include user parameter
ErrCodeEmptyUsernameCode = sferrors.ErrCodeEmptyUsernameCode
// ErrCodeEmptyPasswordCode is an error code for the case where a DSN doesn't include password parameter
ErrCodeEmptyPasswordCode = sferrors.ErrCodeEmptyPasswordCode
// ErrCodeFailedToParseHost is an error code for the case where a DSN includes an invalid host name
ErrCodeFailedToParseHost = sferrors.ErrCodeFailedToParseHost
// ErrCodeFailedToParsePort is an error code for the case where a DSN includes an invalid port number
ErrCodeFailedToParsePort = sferrors.ErrCodeFailedToParsePort
// ErrCodeIdpConnectionError is an error code for the case where a IDP connection failed
ErrCodeIdpConnectionError = sferrors.ErrCodeIdpConnectionError
// ErrCodeSSOURLNotMatch is an error code for the case where a SSO URL doesn't match
ErrCodeSSOURLNotMatch = sferrors.ErrCodeSSOURLNotMatch
// ErrCodeServiceUnavailable is an error code for the case where service is unavailable.
ErrCodeServiceUnavailable = sferrors.ErrCodeServiceUnavailable
// ErrCodeFailedToConnect is an error code for the case where a DB connection failed due to wrong account name
ErrCodeFailedToConnect = sferrors.ErrCodeFailedToConnect
// ErrCodeRegionOverlap is an error code for the case where a region is specified despite an account region present
ErrCodeRegionOverlap = sferrors.ErrCodeRegionOverlap
// ErrCodePrivateKeyParseError is an error code for the case where the private key is not parsed correctly
ErrCodePrivateKeyParseError = sferrors.ErrCodePrivateKeyParseError
// ErrCodeFailedToParseAuthenticator is an error code for the case where a DNS includes an invalid authenticator
ErrCodeFailedToParseAuthenticator = sferrors.ErrCodeFailedToParseAuthenticator
// ErrCodeClientConfigFailed is an error code for the case where clientConfigFile is invalid or applying client configuration fails
ErrCodeClientConfigFailed = sferrors.ErrCodeClientConfigFailed
// ErrCodeTomlFileParsingFailed is an error code for the case where parsing the toml file is failed because of invalid value.
ErrCodeTomlFileParsingFailed = sferrors.ErrCodeTomlFileParsingFailed
// ErrCodeFailedToFindDSNInToml is an error code for the case where the DSN does not exist in the toml file.
ErrCodeFailedToFindDSNInToml = sferrors.ErrCodeFailedToFindDSNInToml
// ErrCodeInvalidFilePermission is an error code for the case where the user does not have 0600 permission to the toml file.
ErrCodeInvalidFilePermission = sferrors.ErrCodeInvalidFilePermission
// ErrCodeEmptyPasswordAndToken is an error code for the case where a DSN do includes neither password nor token
ErrCodeEmptyPasswordAndToken = sferrors.ErrCodeEmptyPasswordAndToken
// ErrCodeEmptyOAuthParameters is an error code for the case where the client ID or client secret are not provided for OAuth flows.
ErrCodeEmptyOAuthParameters = sferrors.ErrCodeEmptyOAuthParameters
// ErrMissingAccessATokenButRefreshTokenPresent is an error code for the case when access token is not found in cache, but the refresh token is present.
ErrMissingAccessATokenButRefreshTokenPresent = sferrors.ErrMissingAccessATokenButRefreshTokenPresent
// ErrCodeMissingTLSConfig is an error code for the case where the TLS config is missing.
ErrCodeMissingTLSConfig = sferrors.ErrCodeMissingTLSConfig
/* network */
// ErrFailedToPostQuery is an error code for the case where HTTP POST failed.
ErrFailedToPostQuery = sferrors.ErrFailedToPostQuery
// ErrFailedToRenewSession is an error code for the case where session renewal failed.
ErrFailedToRenewSession = sferrors.ErrFailedToRenewSession
// ErrFailedToCancelQuery is an error code for the case where cancel query failed.
ErrFailedToCancelQuery = sferrors.ErrFailedToCancelQuery
// ErrFailedToCloseSession is an error code for the case where close session failed.
ErrFailedToCloseSession = sferrors.ErrFailedToCloseSession
// ErrFailedToAuth is an error code for the case where authentication failed for unknown reason.
ErrFailedToAuth = sferrors.ErrFailedToAuth
// ErrFailedToAuthSAML is an error code for the case where authentication via SAML failed for unknown reason.
ErrFailedToAuthSAML = sferrors.ErrFailedToAuthSAML
// ErrFailedToAuthOKTA is an error code for the case where authentication via OKTA failed for unknown reason.
ErrFailedToAuthOKTA = sferrors.ErrFailedToAuthOKTA
// ErrFailedToGetSSO is an error code for the case where authentication via OKTA failed for unknown reason.
ErrFailedToGetSSO = sferrors.ErrFailedToGetSSO
// ErrFailedToParseResponse is an error code for when we cannot parse an external browser response from Snowflake.
ErrFailedToParseResponse = sferrors.ErrFailedToParseResponse
// ErrFailedToGetExternalBrowserResponse is an error code for when there's an error reading from the open socket.
ErrFailedToGetExternalBrowserResponse = sferrors.ErrFailedToGetExternalBrowserResponse
// ErrFailedToHeartbeat is an error code when a heartbeat fails.
ErrFailedToHeartbeat = sferrors.ErrFailedToHeartbeat
/* rows */
// ErrFailedToGetChunk is an error code for the case where it failed to get chunk of result set
ErrFailedToGetChunk = sferrors.ErrFailedToGetChunk
// ErrNonArrowResponseInArrowBatches is an error code for case where ArrowBatches mode is enabled, but response is not Arrow-based
ErrNonArrowResponseInArrowBatches = sferrors.ErrNonArrowResponseInArrowBatches
/* transaction*/
// ErrNoReadOnlyTransaction is an error code for the case where readonly mode is specified.
ErrNoReadOnlyTransaction = sferrors.ErrNoReadOnlyTransaction
// ErrNoDefaultTransactionIsolationLevel is an error code for the case where non default isolation level is specified.
ErrNoDefaultTransactionIsolationLevel = sferrors.ErrNoDefaultTransactionIsolationLevel
/* file transfer */
// ErrInvalidStageFs is an error code denoting an invalid stage in the file system
ErrInvalidStageFs = sferrors.ErrInvalidStageFs
// ErrFailedToDownloadFromStage is an error code denoting the failure to download a file from the stage
ErrFailedToDownloadFromStage = sferrors.ErrFailedToDownloadFromStage
// ErrFailedToUploadToStage is an error code denoting the failure to upload a file to the stage
ErrFailedToUploadToStage = sferrors.ErrFailedToUploadToStage
// ErrInvalidStageLocation is an error code denoting an invalid stage location
ErrInvalidStageLocation = sferrors.ErrInvalidStageLocation
// ErrLocalPathNotDirectory is an error code denoting a local path that is not a directory
ErrLocalPathNotDirectory = sferrors.ErrLocalPathNotDirectory
// ErrFileNotExists is an error code denoting the file to be transferred does not exist
ErrFileNotExists = sferrors.ErrFileNotExists
// ErrCompressionNotSupported is an error code denoting the user specified compression type is not supported
ErrCompressionNotSupported = sferrors.ErrCompressionNotSupported
// ErrInternalNotMatchEncryptMaterial is an error code denoting the encryption material specified does not match
ErrInternalNotMatchEncryptMaterial = sferrors.ErrInternalNotMatchEncryptMaterial
// ErrCommandNotRecognized is an error code denoting the PUT/GET command was not recognized
ErrCommandNotRecognized = sferrors.ErrCommandNotRecognized
// ErrFailedToConvertToS3Client is an error code denoting the failure of an interface to s3.Client conversion
ErrFailedToConvertToS3Client = sferrors.ErrFailedToConvertToS3Client
// ErrNotImplemented is an error code denoting the file transfer feature is not implemented
ErrNotImplemented = sferrors.ErrNotImplemented
// ErrInvalidPadding is an error code denoting the invalid padding of decryption key
ErrInvalidPadding = sferrors.ErrInvalidPadding
/* binding */
// ErrBindSerialization is an error code for a failed serialization of bind variables
ErrBindSerialization = sferrors.ErrBindSerialization
// ErrBindUpload is an error code for the uploading process of bind elements to the stage
ErrBindUpload = sferrors.ErrBindUpload
/* async */
// ErrAsync is an error code for an unknown async error
ErrAsync = sferrors.ErrAsync
/* multi-statement */
// ErrNoResultIDs is an error code for empty result IDs for multi statement queries
ErrNoResultIDs = sferrors.ErrNoResultIDs
/* converter */
// ErrInvalidTimestampTz is an error code for the case where a returned TIMESTAMP_TZ internal value is invalid
ErrInvalidTimestampTz = sferrors.ErrInvalidTimestampTz
// ErrInvalidOffsetStr is an error code for the case where an offset string is invalid. The input string must
// consist of sHHMI where one sign character '+'/'-' followed by zero filled hours and minutes
ErrInvalidOffsetStr = sferrors.ErrInvalidOffsetStr
// ErrInvalidBinaryHexForm is an error code for the case where a binary data in hex form is invalid.
ErrInvalidBinaryHexForm = sferrors.ErrInvalidBinaryHexForm
// ErrTooHighTimestampPrecision is an error code for the case where cannot convert Snowflake timestamp to arrow.Timestamp
ErrTooHighTimestampPrecision = sferrors.ErrTooHighTimestampPrecision
// ErrNullValueInArray is an error code for the case where there are null values in an array without arrayValuesNullable set to true
ErrNullValueInArray = sferrors.ErrNullValueInArray
// ErrNullValueInMap is an error code for the case where there are null values in a map without mapValuesNullable set to true
ErrNullValueInMap = sferrors.ErrNullValueInMap
/* OCSP */
// ErrOCSPStatusRevoked is an error code for the case where the certificate is revoked.
ErrOCSPStatusRevoked = sferrors.ErrOCSPStatusRevoked
// ErrOCSPStatusUnknown is an error code for the case where the certificate revocation status is unknown.
ErrOCSPStatusUnknown = sferrors.ErrOCSPStatusUnknown
// ErrOCSPInvalidValidity is an error code for the case where the OCSP response validity is invalid.
ErrOCSPInvalidValidity = sferrors.ErrOCSPInvalidValidity
// ErrOCSPNoOCSPResponderURL is an error code for the case where the OCSP responder URL is not attached.
ErrOCSPNoOCSPResponderURL = sferrors.ErrOCSPNoOCSPResponderURL
/* query Status*/
// ErrQueryStatus when check the status of a query, receive error or no status
ErrQueryStatus = sferrors.ErrQueryStatus
// ErrQueryIDFormat the query ID given to fetch its result is not valid
ErrQueryIDFormat = sferrors.ErrQueryIDFormat
// ErrQueryReportedError server side reports the query failed with error
ErrQueryReportedError = sferrors.ErrQueryReportedError
// ErrQueryIsRunning the query is still running
ErrQueryIsRunning = sferrors.ErrQueryIsRunning
/* GS error code */
// ErrSessionGone is an GS error code for the case that session is already closed
ErrSessionGone = sferrors.ErrSessionGone
// ErrRoleNotExist is a GS error code for the case that the role specified does not exist
ErrRoleNotExist = sferrors.ErrRoleNotExist
// ErrObjectNotExistOrAuthorized is a GS error code for the case that the server-side object specified does not exist
ErrObjectNotExistOrAuthorized = sferrors.ErrObjectNotExistOrAuthorized
)