@@ -89,27 +89,15 @@ extension SwiftProtobufError {
8989 /// A high level indication of the kind of error being thrown.
9090 public struct Code : Hashable , Sendable , CustomStringConvertible {
9191 private enum Wrapped : Hashable , Sendable , CustomStringConvertible {
92- case binaryEncodingError
9392 case binaryDecodingError
9493 case binaryStreamDecodingError
95- case jsonEncodingError
96-
97- // These are not domains, but rather specific errors for which we
98- // want to have associated types, and thus require special treatment.
99- case anyTypeURLNotRegistered( typeURL: String )
10094
10195 var description : String {
10296 switch self {
103- case . binaryEncodingError:
104- return " Binary encoding error "
10597 case . binaryDecodingError:
10698 return " Binary decoding error "
10799 case . binaryStreamDecodingError:
108100 return " Stream decoding error "
109- case . jsonEncodingError:
110- return " JSON encoding error "
111- case . anyTypeURLNotRegistered( let typeURL) :
112- return " Type URL not registered: \( typeURL) "
113101 }
114102 }
115103 }
@@ -123,11 +111,6 @@ extension SwiftProtobufError {
123111 private init ( _ code: Wrapped ) {
124112 self . code = code
125113 }
126-
127- /// Errors arising from encoding protobufs into binary data.
128- public static var binaryEncodingError : Self {
129- Self ( . binaryEncodingError)
130- }
131114
132115 /// Errors arising from binary decoding of data into protobufs.
133116 public static var binaryDecodingError : Self {
@@ -139,35 +122,6 @@ extension SwiftProtobufError {
139122 public static var binaryStreamDecodingError : Self {
140123 Self ( . binaryStreamDecodingError)
141124 }
142-
143- /// Errors arising from encoding protobufs into JSON.
144- public static var jsonEncodingError : Self {
145- Self ( . jsonEncodingError)
146- }
147-
148- /// `Any` fields that were decoded from JSON cannot be re-encoded to binary
149- /// unless the object they hold is a well-known type or a type registered via
150- /// `Google_Protobuf_Any.register()`.
151- /// This Code refers to errors that arise from this scenario.
152- ///
153- /// - Parameter typeURL: The URL for the unregistered type.
154- /// - Returns: A `SwiftProtobufError.Code`.
155- public static func anyTypeURLNotRegistered( typeURL: String ) -> Self {
156- Self ( . anyTypeURLNotRegistered( typeURL: typeURL) )
157- }
158-
159- /// The unregistered type URL that caused the error, if any is associated with this `Code`.
160- public var unregisteredTypeURL : String ? {
161- switch self . code {
162- case . anyTypeURLNotRegistered( let typeURL) :
163- return typeURL
164- case . binaryEncodingError,
165- . binaryDecodingError,
166- . binaryStreamDecodingError,
167- . jsonEncodingError:
168- return nil
169- }
170- }
171125 }
172126
173127 /// A location within source code.
@@ -213,42 +167,6 @@ extension SwiftProtobufError: CustomDebugStringConvertible {
213167// - MARK: Common errors
214168
215169extension SwiftProtobufError {
216- /// Errors arising from encoding protobufs into binary data.
217- public enum BinaryEncoding {
218- /// Messages are limited to a maximum of 2GB in encoded size.
219- public static func tooLarge(
220- function: String = #function,
221- file: String = #fileID,
222- line: Int = #line
223- ) -> SwiftProtobufError {
224- SwiftProtobufError (
225- code: . binaryEncodingError,
226- message: " Messages are limited to a maximum of 2GB in encoded size. " ,
227- location: SourceLocation ( function: function, file: file, line: line)
228- )
229- }
230-
231- /// `Any` fields that were decoded from JSON cannot be re-encoded to binary
232- /// unless the object they hold is a well-known type or a type registered via
233- /// `Google_Protobuf_Any.register()`.
234- public static func anyTypeURLNotRegistered(
235- typeURL: String ,
236- function: String = #function,
237- file: String = #fileID,
238- line: Int = #line
239- ) -> SwiftProtobufError {
240- SwiftProtobufError (
241- code: . anyTypeURLNotRegistered( typeURL: typeURL) ,
242- message: """
243- Any fields that were decoded from JSON format cannot be re-encoded to binary \
244- unless the object they hold is a well-known type or a type registered via \
245- `Google_Protobuf_Any.register()`. Type URL is \( typeURL) .
246- """ ,
247- location: SourceLocation ( function: function, file: file, line: line)
248- )
249- }
250- }
251-
252170 /// Errors arising from binary decoding of data into protobufs.
253171 public enum BinaryDecoding {
254172 /// Message is too large. Bytes and Strings have a max size of 2GB.
@@ -320,26 +238,4 @@ extension SwiftProtobufError {
320238 )
321239 }
322240 }
323-
324- /// Errors arising from encoding protobufs into JSON.
325- public enum JSONEncoding {
326- /// Any fields that were decoded from binary format cannot be re-encoded into JSON unless the
327- /// object they hold is a well-known type or a type registered via `Google_Protobuf_Any.register()`.
328- public static func anyTypeURLNotRegistered(
329- typeURL: String ,
330- function: String = #function,
331- file: String = #fileID,
332- line: Int = #line
333- ) -> SwiftProtobufError {
334- SwiftProtobufError (
335- code: . anyTypeURLNotRegistered( typeURL: typeURL) ,
336- message: """
337- Any fields that were decoded from binary format cannot be re-encoded into JSON \
338- unless the object they hold is a well-known type or a type registered via \
339- `Google_Protobuf_Any.register()`. Type URL is \( typeURL) .
340- """ ,
341- location: SourceLocation ( function: function, file: file, line: line)
342- )
343- }
344- }
345241}
0 commit comments