Skip to content
Merged
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
32 changes: 28 additions & 4 deletions Sources/GRPC/GRPCTimeout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
import NIO

public enum GRPCTimeoutError: String, Error, Equatable {
case negative = "GRPCTimeout must be non-negative"
case tooManyDigits = "GRPCTimeout must be at most 8 digits"
/// Errors thrown when constructing a timeout.
public struct GRPCTimeoutError: Error, Equatable, CustomStringConvertible {
private enum BaseError {
case negative
case tooManyDigits
}

private var error: BaseError

private init(_ error: BaseError) {
self.error = error
}

public var description: String {
switch self.error {
case .negative:
return "GRPCTimeoutError: time amount must not be negative"
case .tooManyDigits:
return "GRPCTimeoutError: too many digits to represent using the gRPC wire-format"
}
}

/// The timeout is negative.
public static let negative = GRPCTimeoutError(.negative)

/// The number of digits in the timeout amount is more than 8-digits and cannot be encoded in
/// the gRPC wire-format.
public static let tooManyDigits = GRPCTimeoutError(.tooManyDigits)
}

/// A timeout for a gRPC call.
Expand Down