|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the RediStack open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2023 RediStack project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of RediStack project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import NIOCore |
| 16 | + |
| 17 | +/// This error is thrown if a RESP3 package could not be decoded. |
| 18 | +/// |
| 19 | +/// If you see this error, there a two potential reasons this might happen: |
| 20 | +/// |
| 21 | +/// 1. The Swift RESP3 implementation is wrong |
| 22 | +/// 2. You are contacting an untrusted backend |
| 23 | +/// |
| 24 | +struct RESP3ParsingError: Error { |
| 25 | + struct Code: Hashable, Sendable, CustomStringConvertible { |
| 26 | + private enum Base { |
| 27 | + case invalidLeadingByte |
| 28 | + case invalidData |
| 29 | + case tooDeeplyNestedAggregatedTypes |
| 30 | + case missingColonInVerbatimString |
| 31 | + case canNotParseInteger |
| 32 | + case canNotParseDouble |
| 33 | + case canNotParseBigNumber |
| 34 | + } |
| 35 | + |
| 36 | + private let base: Base |
| 37 | + |
| 38 | + private init(_ base: Base) { |
| 39 | + self.base = base |
| 40 | + } |
| 41 | + |
| 42 | + static let invalidLeadingByte = Self.init(.invalidLeadingByte) |
| 43 | + static let invalidData = Self.init(.invalidData) |
| 44 | + static let tooDeeplyNestedAggregatedTypes = Self.init(.tooDeeplyNestedAggregatedTypes) |
| 45 | + static let missingColonInVerbatimString = Self.init(.missingColonInVerbatimString) |
| 46 | + static let canNotParseInteger = Self.init(.canNotParseInteger) |
| 47 | + static let canNotParseDouble = Self.init(.canNotParseDouble) |
| 48 | + static let canNotParseBigNumber = Self.init(.canNotParseBigNumber) |
| 49 | + |
| 50 | + var description: String { |
| 51 | + switch self.base { |
| 52 | + case .invalidLeadingByte: |
| 53 | + return "invalidLeadingByte" |
| 54 | + case .invalidData: |
| 55 | + return "invalidData" |
| 56 | + case .tooDeeplyNestedAggregatedTypes: |
| 57 | + return "tooDeeplyNestedAggregatedTypes" |
| 58 | + case .missingColonInVerbatimString: |
| 59 | + return "missingColonInVerbatimString" |
| 60 | + case .canNotParseInteger: |
| 61 | + return "canNotParseInteger" |
| 62 | + case .canNotParseDouble: |
| 63 | + return "canNotParseDouble" |
| 64 | + case .canNotParseBigNumber: |
| 65 | + return "canNotParseBigNumber" |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + var code: Code |
| 71 | + |
| 72 | + var buffer: ByteBuffer |
| 73 | +} |
| 74 | + |
| 75 | +enum RESP3Error: Error, Equatable { |
| 76 | + case dataMalformed |
| 77 | + case invalidType(UInt8) |
| 78 | + case tooDepplyNestedAggregatedTypes |
| 79 | +} |
0 commit comments