Skip to content

Commit 57168ed

Browse files
committed
Merge branch 'rename-errors' into 'master'
Rename `RedisNIOError` to `RedisClientError` See merge request Mordil/swift-redis-nio-client!72
2 parents 6c39eb3 + 13432f0 commit 57168ed

File tree

7 files changed

+19
-18
lines changed

7 files changed

+19
-18
lines changed

Sources/RedisNIO/Commands/BasicCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ extension RedisClient {
160160
let value = result[0].string,
161161
let position = Int(value)
162162
else {
163-
throw RedisNIOError.assertionFailure(message: "Unexpected value in response: \(result[0])")
163+
throw RedisClientError.assertionFailure(message: "Unexpected value in response: \(result[0])")
164164
}
165165
return position
166166
}

Sources/RedisNIO/Commands/ListCommands.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ extension RedisClient {
442442
.flatMapThrowing {
443443
guard !$0.isNull else { return nil }
444444
guard let response = [RESPValue](fromRESP: $0) else {
445-
throw RedisNIOError.responseConversion(to: [RESPValue].self)
445+
throw RedisClientError.failedRESPConversion(to: [RESPValue].self)
446446
}
447447
assert(response.count == 2, "Unexpected response size returned!")
448448
guard let key = response[0].string else {
449-
throw RedisNIOError.assertionFailure(message: "Unexpected structure in response: \(response)")
449+
throw RedisClientError.assertionFailure(message: "Unexpected structure in response: \(response)")
450450
}
451451
return (key, response[1])
452452
}

Sources/RedisNIO/Commands/SortedSetCommands.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension RedisClient {
3131
let scoreItem = response[scoreIsFirst ? index : index + 1]
3232

3333
guard let score = Double(fromRESP: scoreItem) else {
34-
throw RedisNIOError.assertionFailure(message: "Unexpected response: '\(scoreItem)'")
34+
throw RedisClientError.assertionFailure(message: "Unexpected response: '\(scoreItem)'")
3535
}
3636

3737
let elementIndex = scoreIsFirst ? index + 1 : index
@@ -456,14 +456,14 @@ extension RedisClient {
456456
.flatMapThrowing {
457457
guard !$0.isNull else { return nil }
458458
guard let response = [RESPValue](fromRESP: $0) else {
459-
throw RedisNIOError.responseConversion(to: [RESPValue].self)
459+
throw RedisClientError.failedRESPConversion(to: [RESPValue].self)
460460
}
461461
assert(response.count == 3, "Unexpected response size returned!")
462462
guard
463463
let key = response[0].string,
464464
let score = Double(fromRESP: response[1])
465465
else {
466-
throw RedisNIOError.assertionFailure(message: "Unexpected structure in response: \(response)")
466+
throw RedisClientError.assertionFailure(message: "Unexpected structure in response: \(response)")
467467
}
468468
return (key, score, response[2])
469469
}

Sources/RedisNIO/Extensions/SwiftNIO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension EventLoopFuture where Value == RESPValue {
3030
{
3131
return self.flatMapThrowing {
3232
guard let value = T(fromRESP: $0) else {
33-
throw RedisNIOError.responseConversion(to: type)
33+
throw RedisClientError.failedRESPConversion(to: type)
3434
}
3535
return value
3636
}

Sources/RedisNIO/RedisConnection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ extension RedisConnection {
183183
/// If a `RedisError` is returned, the future will be failed instead.
184184
public func send(command: String, with arguments: [RESPValue]) -> EventLoopFuture<RESPValue> {
185185
guard self.isConnected else {
186-
let error = RedisNIOError.connectionClosed
186+
let error = RedisClientError.connectionClosed
187187
logger.warning("\(error.localizedDescription)")
188188
return self.channel.eventLoop.makeFailedFuture(error)
189189
}

Sources/RedisNIO/RedisError.swift renamed to Sources/RedisNIO/RedisErrors.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,29 @@
1414

1515
import protocol Foundation.LocalizedError
1616

17-
/// When working with RedisNIO, several errors are thrown to indicate problems
18-
/// with state, assertions, or otherwise.
19-
public enum RedisNIOError: LocalizedError {
17+
/// When working with `RedisClient`, runtime errors can be thrown to indicate problems with connection state, decoding assertions, or otherwise.
18+
public enum RedisClientError: LocalizedError {
19+
/// The connection is closed, but was used to try and send a command to Redis.
2020
case connectionClosed
21-
case responseConversion(to: Any.Type)
22-
case unsupportedOperation(method: StaticString, message: String)
21+
/// Conversion from `RESPValue` to the specified type failed.
22+
/// If this is ever triggered, please capture the original `RESPValue` value.
23+
case failedRESPConversion(to: Any.Type)
24+
/// Expectations of message structures were not met.
25+
/// If this is ever triggered, please capture the original byte message from Redis along with the command and arguments to Redis.
2326
case assertionFailure(message: String)
2427

2528
public var errorDescription: String? {
2629
let message: String
2730
switch self {
2831
case .connectionClosed: message = "Connection was closed while trying to send command."
29-
case let .responseConversion(type): message = "Failed to convert RESP to \(type)"
30-
case let .unsupportedOperation(method, helpText): message = "\(method) - \(helpText)"
32+
case let .failedRESPConversion(type): message = "Failed to convert RESP to \(type)"
3133
case let .assertionFailure(text): message = text
3234
}
3335
return "RedisNIO: \(message)"
3436
}
3537
}
3638

37-
/// When sending commands to a Redis server, errors caught will be returned as an error message.
38-
/// These messages are represented by `RedisError` instances.
39+
/// 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.
3940
public struct RedisError: LocalizedError {
4041
public let message: String
4142

Tests/RedisNIOTests/RedisConnectionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class RedisConnectionTests: RedisIntegrationTestCase {
4242
_ = try self.connection.ping().wait()
4343
XCTFail("ping() should throw when connection is closed.")
4444
} catch {
45-
XCTAssertTrue(error is RedisNIOError)
45+
XCTAssertTrue(error is RedisClientError)
4646
}
4747
}
4848

0 commit comments

Comments
 (0)