mirror of
https://github.com/swift-server/RediStack.git
synced 2026-06-02 07:37:33 +00:00
Merge branch 'rename-errors' into 'master'
Rename `RedisNIOError` to `RedisClientError` See merge request Mordil/swift-redis-nio-client!72
This commit is contained in:
@@ -160,7 +160,7 @@ extension RedisClient {
|
||||
let value = result[0].string,
|
||||
let position = Int(value)
|
||||
else {
|
||||
throw RedisNIOError.assertionFailure(message: "Unexpected value in response: \(result[0])")
|
||||
throw RedisClientError.assertionFailure(message: "Unexpected value in response: \(result[0])")
|
||||
}
|
||||
return position
|
||||
}
|
||||
|
||||
@@ -442,11 +442,11 @@ extension RedisClient {
|
||||
.flatMapThrowing {
|
||||
guard !$0.isNull else { return nil }
|
||||
guard let response = [RESPValue](fromRESP: $0) else {
|
||||
throw RedisNIOError.responseConversion(to: [RESPValue].self)
|
||||
throw RedisClientError.failedRESPConversion(to: [RESPValue].self)
|
||||
}
|
||||
assert(response.count == 2, "Unexpected response size returned!")
|
||||
guard let key = response[0].string else {
|
||||
throw RedisNIOError.assertionFailure(message: "Unexpected structure in response: \(response)")
|
||||
throw RedisClientError.assertionFailure(message: "Unexpected structure in response: \(response)")
|
||||
}
|
||||
return (key, response[1])
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ extension RedisClient {
|
||||
let scoreItem = response[scoreIsFirst ? index : index + 1]
|
||||
|
||||
guard let score = Double(fromRESP: scoreItem) else {
|
||||
throw RedisNIOError.assertionFailure(message: "Unexpected response: '\(scoreItem)'")
|
||||
throw RedisClientError.assertionFailure(message: "Unexpected response: '\(scoreItem)'")
|
||||
}
|
||||
|
||||
let elementIndex = scoreIsFirst ? index + 1 : index
|
||||
@@ -456,14 +456,14 @@ extension RedisClient {
|
||||
.flatMapThrowing {
|
||||
guard !$0.isNull else { return nil }
|
||||
guard let response = [RESPValue](fromRESP: $0) else {
|
||||
throw RedisNIOError.responseConversion(to: [RESPValue].self)
|
||||
throw RedisClientError.failedRESPConversion(to: [RESPValue].self)
|
||||
}
|
||||
assert(response.count == 3, "Unexpected response size returned!")
|
||||
guard
|
||||
let key = response[0].string,
|
||||
let score = Double(fromRESP: response[1])
|
||||
else {
|
||||
throw RedisNIOError.assertionFailure(message: "Unexpected structure in response: \(response)")
|
||||
throw RedisClientError.assertionFailure(message: "Unexpected structure in response: \(response)")
|
||||
}
|
||||
return (key, score, response[2])
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ extension EventLoopFuture where Value == RESPValue {
|
||||
{
|
||||
return self.flatMapThrowing {
|
||||
guard let value = T(fromRESP: $0) else {
|
||||
throw RedisNIOError.responseConversion(to: type)
|
||||
throw RedisClientError.failedRESPConversion(to: type)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ extension RedisConnection {
|
||||
/// If a `RedisError` is returned, the future will be failed instead.
|
||||
public func send(command: String, with arguments: [RESPValue]) -> EventLoopFuture<RESPValue> {
|
||||
guard self.isConnected else {
|
||||
let error = RedisNIOError.connectionClosed
|
||||
let error = RedisClientError.connectionClosed
|
||||
logger.warning("\(error.localizedDescription)")
|
||||
return self.channel.eventLoop.makeFailedFuture(error)
|
||||
}
|
||||
|
||||
@@ -14,28 +14,29 @@
|
||||
|
||||
import protocol Foundation.LocalizedError
|
||||
|
||||
/// When working with RedisNIO, several errors are thrown to indicate problems
|
||||
/// with state, assertions, or otherwise.
|
||||
public enum RedisNIOError: LocalizedError {
|
||||
/// When working with `RedisClient`, runtime errors can be thrown to indicate problems with connection state, decoding assertions, or otherwise.
|
||||
public enum RedisClientError: LocalizedError {
|
||||
/// The connection is closed, but was used to try and send a command to Redis.
|
||||
case connectionClosed
|
||||
case responseConversion(to: Any.Type)
|
||||
case unsupportedOperation(method: StaticString, message: String)
|
||||
/// Conversion from `RESPValue` to the specified type failed.
|
||||
/// If this is ever triggered, please capture the original `RESPValue` value.
|
||||
case failedRESPConversion(to: Any.Type)
|
||||
/// Expectations of message structures were not met.
|
||||
/// If this is ever triggered, please capture the original byte message from Redis along with the command and arguments to Redis.
|
||||
case assertionFailure(message: String)
|
||||
|
||||
public var errorDescription: String? {
|
||||
let message: String
|
||||
switch self {
|
||||
case .connectionClosed: message = "Connection was closed while trying to send command."
|
||||
case let .responseConversion(type): message = "Failed to convert RESP to \(type)"
|
||||
case let .unsupportedOperation(method, helpText): message = "\(method) - \(helpText)"
|
||||
case let .failedRESPConversion(type): message = "Failed to convert RESP to \(type)"
|
||||
case let .assertionFailure(text): message = text
|
||||
}
|
||||
return "RedisNIO: \(message)"
|
||||
}
|
||||
}
|
||||
|
||||
/// When sending commands to a Redis server, errors caught will be returned as an error message.
|
||||
/// These messages are represented by `RedisError` instances.
|
||||
/// If something goes wrong with a command within Redis, it will respond with an error that is captured and represented by instances of this type.
|
||||
public struct RedisError: LocalizedError {
|
||||
public let message: String
|
||||
|
||||
@@ -42,7 +42,7 @@ final class RedisConnectionTests: RedisIntegrationTestCase {
|
||||
_ = try self.connection.ping().wait()
|
||||
XCTFail("ping() should throw when connection is closed.")
|
||||
} catch {
|
||||
XCTAssertTrue(error is RedisNIOError)
|
||||
XCTAssertTrue(error is RedisClientError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user