Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add custom strings to print response types and values if applicable #103

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Momento/messages/responses/ResponseBase.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class ErrorResponseBase: ErrorResponseBaseProtocol {
public class ErrorResponseBase: ErrorResponseBaseProtocol, CustomStringConvertible {
var error: SdkError
public var message: String { return self.error.message }
public var errorCode: MomentoErrorCode { return self.error.errorCode }
Expand All @@ -9,6 +9,6 @@ public class ErrorResponseBase: ErrorResponseBaseProtocol {
}

public var description: String {
return "Error: \(self.errorCode) \(self.error.messageWrapper): \(self.error.message)"
return "[\(self.errorCode)] \(self.error.messageWrapper): \(self.error.message)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum ListCachesResponse {
}

/// Indicates a successful list caches request.
public class ListCachesSuccess {
public class ListCachesSuccess: CustomStringConvertible {
/// An array of `CacheInfo` objects, containing information about each cache.
public let caches: [CacheInfo]

Expand All @@ -35,6 +35,10 @@ public class ListCachesSuccess {
return CacheInfo(name: cache.cacheName)
})
}

public var description: String {
return "[\(type(of: self))] Length of caches list: \(self.caches.count)"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ public enum ListConcatenateBackResponse {
}

/// Indicates a successful list concatenate back request.
public class ListConcatenateBackSuccess {
public class ListConcatenateBackSuccess: CustomStringConvertible {
/// The new length of the list after the concatenate operation.
public let listLength: UInt32

init(length: UInt32) {
self.listLength = length
}

public var description: String {
return "[\(type(of: self))] List length post-concatenation: \(self.listLength)"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ public enum ListConcatenateFrontResponse {
}

/// Indicates a successful list concatenate front request.
public class ListConcatenateFrontSuccess {
public class ListConcatenateFrontSuccess: CustomStringConvertible {
/// The new length of the list after the concatenate operation.
public let listLength: UInt32

init(length: UInt32) {
self.listLength = length
}

public var description: String {
return "[\(type(of: self))] List length post-concatenation: \(self.listLength)"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum ListFetchResponse {
}

/// Indicates that the requested list was successfully retrieved from the cache and can be accessed by the fields `valueListString` or `valueListData`.
public class ListFetchHit {
public class ListFetchHit: CustomStringConvertible {
/// List values as type String
public let valueListString: [String]
/// List values as type Data
Expand All @@ -32,6 +32,10 @@ public class ListFetchHit {
self.valueListData = values
self.valueListString = values.map { String(decoding: $0, as: UTF8.self) }
}

public var description: String {
return "[\(type(of: self))] List length: \(self.valueListData.count)"
}
}

/// Indicates that the requested data was not available in the cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ public enum ListLengthResponse {
}

/// Indicates that the length of requested list was successfully retrieved from the cache.
public class ListLengthHit {
public class ListLengthHit: CustomStringConvertible {
public let length: UInt32

init(length: UInt32) {
self.length = length
}

public var description: String {
return "[\(type(of: self))] List length: \(self.length)"
}
}

/// Indicates that the requested list was not available in the cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum ListPopBackResponse {
}

/// Indicates that the requested data was successfully retrieved from the cache and can be accessed by the fields `valueString` or `valueData`.
public class ListPopBackHit {
public class ListPopBackHit: CustomStringConvertible {
/// Popped value as String
public let valueString: String
/// Popped value as Data
Expand All @@ -32,6 +32,10 @@ public class ListPopBackHit {
self.valueData = value
self.valueString = String(decoding: value, as: UTF8.self)
}

public var description: String {
return "[\(type(of: self))] Popped value: \(self.valueString)"
}
}

/// Indicates that the requested data was not available in the cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum ListPopFrontResponse {
}

/// Indicates that the requested data was successfully retrieved from the cache and can be accessed by the fields `valueString` or `valueData`.
public class ListPopFrontHit {
public class ListPopFrontHit: CustomStringConvertible {
/// Popped value as String
public let valueString: String
/// Popped value as Data
Expand All @@ -32,6 +32,10 @@ public class ListPopFrontHit {
self.valueData = value
self.valueString = String(decoding: value, as: UTF8.self)
}

public var description: String {
return "[\(type(of: self))] Popped value: \(self.valueString)"
}
}

/// Indicates that the requested data was not available in the cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ public enum ListPushBackResponse {
}

/// Indicates a successful list push back request.
public class ListPushBackSuccess {
public class ListPushBackSuccess: CustomStringConvertible {
/// The new length of the list after the push back operation.
public let listLength: UInt32

init(length: UInt32) {
self.listLength = length
}

public var description: String {
return "[\(type(of: self))] List length after push: \(self.listLength)"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ public enum ListPushFrontResponse {
}

/// Indicates a successful list push front request.
public class ListPushFrontSuccess {
public class ListPushFrontSuccess: CustomStringConvertible {
/// The new length of the list after the push front operation.
public let listLength: UInt32

init(length: UInt32) {
self.listLength = length
}

public var description: String {
return "[\(type(of: self))] List length after push: \(self.listLength)"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum GetResponse {
}

/// Indicates that the requested data was successfully retrieved from the cache and can be accessed by the fields `valueString` or `valueData`.
public class GetHit: Equatable {
public class GetHit: Equatable, CustomStringConvertible {
/// Cache item value as type String
public let valueString: String
/// Cache item value as type Data
Expand All @@ -36,6 +36,10 @@ public class GetHit: Equatable {
public static func == (lhs: GetHit, rhs: GetHit) -> Bool {
return lhs.valueData == rhs.valueData
}

public var description: String {
return "[\(type(of: self))] Value: \(self.valueString)"
}
}

/// Indicates that the requested data was not available in the cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ public enum TopicSubscriptionItemResponse {
}

/// Topic subscription item that was recieved as type String and can be accessed using the `value` field
public class TopicSubscriptionItemText {
public class TopicSubscriptionItemText: CustomStringConvertible {
public let value: String

init(value: String) {
self.value = value
}

public var description: String {
return "[\(type(of: self))] Value: \(self.value)"
}
}

/// Topic subscription item that was recieved as type Data and can be accessed using the `value` field
public class TopicSubscriptionItemBinary {
public class TopicSubscriptionItemBinary: CustomStringConvertible {
public let value: Data

init(value: Data) {
self.value = value
}

public var description: String {
return "[\(type(of: self))] Value: \(String(decoding: self.value, as: UTF8.self))"
}
}

/**
Expand Down
Loading