forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
146 lines (130 loc) · 7.23 KB
/
errors.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
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
// Copyright (c) 2017-2018 Snowflake Computing Inc. All right reserved.
package gosnowflake
import (
"fmt"
)
// SnowflakeError is a error type including various Snowflake specific information.
type SnowflakeError struct {
Number int
SQLState string
QueryID string
Message string
MessageArgs []interface{}
IncludeQueryID bool // TODO: populate this in connection
}
func (se *SnowflakeError) Error() string {
message := se.Message
if len(se.MessageArgs) > 0 {
message = fmt.Sprintf(se.Message, se.MessageArgs...)
}
if se.SQLState != "" {
if se.IncludeQueryID {
return fmt.Sprintf("%06d (%s): %s: %s", se.Number, se.SQLState, se.QueryID, message)
}
return fmt.Sprintf("%06d (%s): %s", se.Number, se.SQLState, message)
}
if se.IncludeQueryID {
return fmt.Sprintf("%06d: %s: %s", se.Number, se.QueryID, message)
}
return fmt.Sprintf("%06d: %s", se.Number, message)
}
const (
/* connection */
// ErrCodeEmptyAccountCode is an error code for the case where a DNS doesn't include account parameter
ErrCodeEmptyAccountCode = 260000
// ErrCodeEmptyUsernameCode is an error code for the case where a DNS doesn't include user parameter
ErrCodeEmptyUsernameCode = 260001
// ErrCodeEmptyPasswordCode is an error code for the case where a DNS doesn't include password parameter
ErrCodeEmptyPasswordCode = 260002
// ErrCodeFailedToParseHost is an error code for the case where a DNS includes an invalid host name
ErrCodeFailedToParseHost = 260003
// ErrCodeFailedToParsePort is an error code for the case where a DNS includes an invalid port number
ErrCodeFailedToParsePort = 260004
// ErrCodeIdpConnectionError is an error code for the case where a IDP connection failed
ErrCodeIdpConnectionError = 260005
// ErrCodeSSOURLNotMatch is an error code for the case where a SSO URL doesn't match
ErrCodeSSOURLNotMatch = 260006
// ErrCodeServiceUnavailable is an error code for the case where service is unavailable.
ErrCodeServiceUnavailable = 260007
// ErrCodeFailedToConnect is an error code for the case where a DB connection failed due to wrong account name
ErrCodeFailedToConnect = 260008
// ErrCodeObjectNotExists is an error code for the case where the specified database object doesn't exist
ErrCodeObjectNotExists = 260009
/* network */
// ErrFailedToPostQuery is an error code for the case where HTTP POST failed.
ErrFailedToPostQuery = 261000
// ErrFailedToRenewSession is an error code for the case where session renewal failed.
ErrFailedToRenewSession = 261001
// ErrFailedToCancelQuery is an error code for the case where cancel query failed.
ErrFailedToCancelQuery = 261002
// ErrFailedToCloseSession is an error code for the case where close session failed.
ErrFailedToCloseSession = 261003
// ErrFailedToAuth is an error code for the case where authentication failed for unknown reason.
ErrFailedToAuth = 261004
// ErrFailedToAuthSAML is an error code for the case where authentication via SAML failed for unknown reason.
ErrFailedToAuthSAML = 261005
// ErrFailedToAuthOKTA is an error code for the case where authentication via OKTA failed for unknown reason.
ErrFailedToAuthOKTA = 261006
// ErrFailedToGetSSO is an error code for the case where authentication via OKTA failed for unknown reason.
ErrFailedToGetSSO = 261007
// ErrFailedToParseResponse is an error code for when we cannot parse an external browser response from Snowflake.
ErrFailedToParseResponse = 261008
// ErrFailedToGetExternalBrowserResponse is an error code for when there's an error reading from the open socket.
ErrFailedToGetExternalBrowserResponse = 261009
/* rows */
// ErrFailedToGetChunk is an error code for the case where it failed to get chunk of result set
ErrFailedToGetChunk = 262000
/* transaction*/
// ErrNoReadOnlyTransaction is an error code for the case where readonly mode is specified.
ErrNoReadOnlyTransaction = 263000
// ErrNoDefaultTransactionIsolationLevel is an error code for the case where non default isolation level is specified.
ErrNoDefaultTransactionIsolationLevel = 263001
/* converter */
// ErrInvalidTimestampTz is an error code for the case where a returned TIMESTAMP_TZ internal value is invalid
ErrInvalidTimestampTz = 268000
// ErrInvalidOffsetStr is an error code for the case where a offset string is invalid. The input string must
// consist of sHHMI where one sign character '+'/'-' followed by zero filled hours and minutes
ErrInvalidOffsetStr = 268001
// ErrInvalidBinaryHexForm is an error code for the case where a binary data in hex form is invalid.
ErrInvalidBinaryHexForm = 268002
)
const (
errMsgFailedToParseHost = "failed to parse a host name. host: %v"
errMsgFailedToParsePort = "failed to parse a port number. port: %v"
errMsgInvalidOffsetStr = "offset must be a string consist of sHHMI where one sign character '+'/'-' followed by zero filled hours and minutes: %v"
errMsgInvalidByteArray = "invalid byte array: %v"
errMsgIdpConnectionError = "failed to verify URLs. authenticator: %v, token URL:%v, SSO URL:%v"
errMsgSSOURLNotMatch = "SSO URL didn't match. expected: %v, got: %v"
errMsgFailedToGetChunk = "failed to get a chunk of result sets. idx: %v"
errMsgFailedToPostQuery = "failed to POST. HTTP: %v, URL: %v"
errMsgFailedToRenew = "failed to renew session. HTTP: %v, URL: %v"
errMsgFailedToCancelQuery = "failed to cancel query. HTTP: %v, URL: %v"
errMsgFailedToCloseSession = "failed to close session. HTTP: %v, URL: %v"
errMsgFailedToAuth = "failed to auth for unknown reason. HTTP: %v, URL: %v"
errMsgFailedToAuthSAML = "failed to auth via SAML for unknown reason. HTTP: %v, URL: %v"
errMsgFailedToAuthOKTA = "failed to auth via OKTA for unknown reason. HTTP: %v, URL: %v"
errMsgFailedToGetSSO = "failed to auth via OKTA for unknown reason. HTTP: %v, URL: %v"
errMsgFailedToParseResponse = "failed to parse a response from Snowflake. Response: %v"
errMsgFailedToGetExternalBrowserResponse = "failed to get an external browser response from Snowflake, err: %s"
errMsgNoReadOnlyTransaction = "no readonly mode is supported"
errMsgNoDefaultTransactionIsolationLevel = "no default isolation transaction level is supported"
errMsgServiceUnavailable = "service is unavailable. check your connectivity. you may need a proxy server. HTTP: %v, URL: %v"
errMsgFailedToConnect = "failed to connect to db. verify account name is correct. HTTP: %v, URL: %v"
errMsgObjectNotExists = "specified object doesn't exists: %v"
)
var (
// ErrEmptyAccount is returned if a DNS doesn't include account parameter.
ErrEmptyAccount = &SnowflakeError{
Number: ErrCodeEmptyAccountCode,
Message: "account is empty",
}
// ErrEmptyUsername is returned if a DNS doesn't include user parameter.
ErrEmptyUsername = &SnowflakeError{
Number: ErrCodeEmptyUsernameCode,
Message: "user is empty",
}
// ErrEmptyPassword is returned if a DNS doesn't include password parameter.
ErrEmptyPassword = &SnowflakeError{
Number: ErrCodeEmptyPasswordCode,
Message: "password is empty"}
)