forked from vapor/mysql-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySQLError.swift
52 lines (47 loc) · 2.02 KB
/
MySQLError.swift
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
import Foundation
public enum MySQLError: Error, CustomStringConvertible, LocalizedError {
case secureConnectionRequired
case unsupportedAuthPlugin(name: String)
case authPluginDataError(name: String)
case missingOrInvalidAuthMoreDataStatusTag
case missingOrInvalidAuthPluginInlineCommand(command: UInt8?)
case missingAuthPluginInlineData
case unsupportedServer(message: String)
case protocolError
case server(MySQLProtocol.ERR_Packet)
case closed
/// A uniqueness constraint was violated. Associated value is message from server with details.
case duplicateEntry(String)
public var message: String {
switch self {
case .secureConnectionRequired:
return "A secure connection to the server is required for authentication."
case .unsupportedAuthPlugin(let name):
return "Unsupported auth plugin name: \(name)"
case .authPluginDataError(let name):
return "Auth plugin (name: \(name)) sent invalid authentication data."
case .missingOrInvalidAuthMoreDataStatusTag:
return "Auth plugin didn't send a correct status tag per protocol."
case .missingOrInvalidAuthPluginInlineCommand(let byte):
return "Auth plugin sent \(byte.map { "\($0)" } ?? "<nothing>"), which we can't interpret."
case .missingAuthPluginInlineData:
return "Auth plugin was supposed to send us some data."
case .unsupportedServer(let message):
return "Unsupported server: \(message)"
case .protocolError:
return "Unknown protocol error"
case .server(let error):
return "Server error: \(error.errorMessage)"
case .closed:
return "Connection closed."
case .duplicateEntry(let message):
return "Duplicate entry: \(message)"
}
}
public var description: String {
return "MySQL error: \(self.message)"
}
public var errorDescription: String? {
return self.description
}
}