-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy patherrors.go
More file actions
115 lines (89 loc) · 4.15 KB
/
errors.go
File metadata and controls
115 lines (89 loc) · 4.15 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
package errors
import (
"fmt"
"time"
"github.com/pkg/errors"
)
// Error messages
const (
// Driver errors
ErrNotImplemented = "not implemented"
ErrTransactionsNotSupported = "transactions are not supported"
ErrReadQueryStatus = "could not read query status"
ErrSentinelTimeout = "sentinel timed out waiting for operation to complete"
ErrParametersNotSupported = "query parameters are not supported by this server"
ErrMixedNamedAndPositionalParameters = "named and positional parameters cannot be used simultaneously"
// Transaction errors
ErrTransactionBegin = "failed to begin transaction"
ErrTransactionCommit = "failed to commit transaction"
ErrTransactionRollback = "failed to rollback transaction"
ErrTransactionNested = "transaction already in progress"
ErrUnsupportedIsolation = "unsupported transaction isolation level"
// Request error messages (connection, authentication, network error)
ErrCloseConnection = "failed to close connection"
ErrThriftClient = "error initializing thrift client"
ErrInvalidURL = "invalid URL"
ErrNoAuthenticationMethod = "no authentication method set"
ErrNoDefaultAuthenticator = "unable to create default authenticator"
ErrInvalidDSNFormat = "invalid DSN: invalid format"
ErrInvalidDSNPort = "invalid DSN: invalid DSN port"
ErrInvalidDSNPATIsEmpty = "invalid DSN: empty token"
ErrBasicAuthNotSupported = "invalid DSN: basic auth not enabled"
ErrInvalidDSNM2m = "invalid DSN: clientId and clientSecret params required"
// Execution error messages (query failure)
ErrQueryExecution = "failed to execute query"
ErrLinkExpired = "link expired"
)
func InvalidDSNFormat(param string, value string, expected string) string {
return fmt.Sprintf("invalid DSN: param %s with value %s is not of type %s", param, value, expected)
}
func ErrInvalidOperationState(state string) string {
return fmt.Sprintf("invalid operation state %s. This should not have happened", state)
}
func ErrUnexpectedOperationState(state string) string {
return fmt.Sprintf("unexpected operation state %s", state)
}
// value to be used with errors.Is() to determine if an error chain contains a request error
var RequestError error = errors.New("Request Error")
// value to be used with errors.Is() to determine if an error chain contains a driver error
var DriverError error = errors.New("Driver Error")
// value to be used with errors.Is() to determine if an error chain contains an execution error
var ExecutionError error = errors.New("Execution Error")
// value to be used with errors.Is() to determine if an error chain contains any databricks error
var DatabricksError error = errors.New("Databricks Error")
// Base interface for driver errors
type DBError interface {
// Descriptive message describing the error
Error() string
// User specified id to track what happens under a request. Useful to track multiple connections in the same request.
// Appears in log messages as field corrId. See driverctx.NewContextWithCorrelationId()
CorrelationId() string
// Internal id to track what happens under a connection. Connections can be reused so this would track across queries.
// Appears in log messages as field connId.
ConnectionId() string
// Stack trace associated with the error. May be nil.
StackTrace() errors.StackTrace
// Underlying causative error. May be nil.
Cause() error
IsRetryable() bool
RetryAfter() time.Duration
}
// An error that is caused by an invalid request.
// Example: permission denied, or the user tries to access a warehouse that doesn’t exist
type DBRequestError interface {
DBError
}
// A fault that is caused by Databricks services
type DBDriverError interface {
DBError
}
// Any error that occurs after the SQL statement has been accepted (e.g. SQL syntax error).
type DBExecutionError interface {
DBError
// Internal id to track what happens under a query.
// Appears in log messages as field queryId.
QueryId() string
// Optional portable error identifier across SQL engines.
// See https://github.com/apache/spark/tree/master/core/src/main/resources/error#ansiiso-standard
SqlState() string
}