Skip to content

Commit d702121

Browse files
committed
Add Equatable conformance for RedisError
Motivation: There is a reasonable way to compare if two `RedisErrors` are equal, which was seen as needed in the `Equatable` conformance for `RESPValue`. Modifications: Added `Equatable` conformance for `RedisError` by comparing the messages. Result: Two `RedisError` instances are now equatable.
1 parent 1d21f66 commit d702121

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

Sources/RediStack/RESP/RESPValue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extension RESPValue: Equatable {
138138
case (.bulkString(let lhs), .bulkString(let rhs)): return lhs == rhs
139139
case (.simpleString(let lhs), .simpleString(let rhs)): return lhs == rhs
140140
case (.integer(let lhs), .integer(let rhs)): return lhs == rhs
141-
case (.error(let lhs), .error(let rhs)): return lhs.message == rhs.message
141+
case (.error(let lhs), .error(let rhs)): return lhs == rhs
142142
case (.array(let lhs), .array(let rhs)): return lhs == rhs
143143
case (.null, .null): return true
144144
default: return false

Sources/RediStack/RedisErrors.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ public enum RedisClientError: LocalizedError {
3737
}
3838

3939
/// 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.
40-
public struct RedisError: LocalizedError {
40+
public struct RedisError: LocalizedError, Equatable {
4141
public let message: String
4242

4343
public var errorDescription: String? { return message }
4444

4545
public init(reason: String) {
4646
message = "Redis: \(reason)"
4747
}
48+
49+
public static func == (lhs: RedisError, rhs: RedisError) -> Bool {
50+
return lhs.message == rhs.message
51+
}
4852
}

Tests/RediStackTests/ChannelHandlers/RedisByteDecoderTests.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,3 @@ extension RedisByteDecoderTests {
299299
return try decoder.decode(context: context, buffer: &buffer)
300300
}
301301
}
302-
303-
extension RedisError: Equatable {
304-
public static func == (lhs: RedisError, rhs: RedisError) -> Bool {
305-
return lhs.message == rhs.message
306-
}
307-
}

0 commit comments

Comments
 (0)