@@ -56,11 +56,7 @@ final class URIValueFromNodeDecoder {
5656 /// - data: The data to parse.
5757 /// - rootKey: The key of the root object.
5858 /// - configuration: The configuration of the decoder.
59- init (
60- data: Substring ,
61- rootKey: URIParsedKeyComponent ,
62- configuration: URICoderConfiguration
63- ) {
59+ init ( data: Substring , rootKey: URIParsedKeyComponent , configuration: URICoderConfiguration ) {
6460 self . rootKey = rootKey
6561 self . dateTranscoder = configuration. dateTranscoder
6662 self . configuration = configuration
@@ -144,6 +140,7 @@ extension URIValueFromNodeDecoder {
144140 /// Use the root as a primitive value.
145141 /// - Parameter work: The closure in which to use the value.
146142 /// - Returns: Any value returned from the closure.
143+ /// - Throws: When parsing the root fails.
147144 private func withParsedRootAsPrimitive< R> ( _ work: ( URIDecodedPrimitive ? ) throws -> R ) throws -> R {
148145 let value : URIDecodedPrimitive ?
149146 if let cached = cache. primitive {
@@ -165,6 +162,7 @@ extension URIValueFromNodeDecoder {
165162 /// Use the root as an array.
166163 /// - Parameter work: The closure in which to use the value.
167164 /// - Returns: Any value returned from the closure.
165+ /// - Throws: When parsing the root fails.
168166 private func withParsedRootAsArray< R> ( _ work: ( URIDecodedArray ) throws -> R ) throws -> R {
169167 let value : URIDecodedArray
170168 if let cached = cache. array {
@@ -186,6 +184,7 @@ extension URIValueFromNodeDecoder {
186184 /// Use the root as a dictionary.
187185 /// - Parameter work: The closure in which to use the value.
188186 /// - Returns: Any value returned from the closure.
187+ /// - Throws: When parsing the root fails.
189188 private func withParsedRootAsDictionary< R> ( _ work: ( URIDecodedDictionary ) throws -> R ) throws -> R {
190189 let value : URIDecodedDictionary
191190 if let cached = cache. dictionary {
@@ -234,6 +233,7 @@ extension URIValueFromNodeDecoder {
234233 /// - key: The key for which to return the value.
235234 /// - dictionary: The dictionary in which to find the value.
236235 /// - Returns: The value in the dictionary, or nil if not found.
236+ /// - Throws: When multiple values are found for the key.
237237 func primitiveValue( forKey key: String , in dictionary: URIDecodedDictionary ) throws -> URIParsedValue ? {
238238 let values = dictionary [ key [ ... ] , default: [ ] ]
239239 if values. isEmpty { return nil }
@@ -246,6 +246,7 @@ extension URIValueFromNodeDecoder {
246246 /// Use the current top of the stack as a primitive value.
247247 /// - Parameter work: The closure in which to use the value.
248248 /// - Returns: Any value returned from the closure.
249+ /// - Throws: When parsing the root fails.
249250 private func withCurrentPrimitiveElement< R> ( _ work: ( URIDecodedPrimitive ? ) throws -> R ) throws -> R {
250251 if !codingStack. isEmpty {
251252 // Nesting is involved.
@@ -285,6 +286,7 @@ extension URIValueFromNodeDecoder {
285286 /// Use the current top of the stack as an array.
286287 /// - Parameter work: The closure in which to use the value.
287288 /// - Returns: Any value returned from the closure.
289+ /// - Throws: When parsing the root fails.
288290 private func withCurrentArrayElements< R> ( _ work: ( URIDecodedArray ) throws -> R ) throws -> R {
289291 if let nestedArrayParentKey = codingStack. first {
290292 // Top level is dictionary, first level nesting is array.
@@ -301,6 +303,7 @@ extension URIValueFromNodeDecoder {
301303 /// Use the current top of the stack as a dictionary.
302304 /// - Parameter work: The closure in which to use the value.
303305 /// - Returns: Any value returned from the closure.
306+ /// - Throws: When parsing the root fails or if there is unsupported extra nesting of containers.
304307 private func withCurrentDictionaryElements< R> ( _ work: ( URIDecodedDictionary ) throws -> R ) throws -> R {
305308 if !codingStack. isEmpty {
306309 try throwMismatch ( " Nesting a dictionary inside another container is not supported. " )
@@ -314,22 +317,26 @@ extension URIValueFromNodeDecoder {
314317
315318 /// Returns the current top-of-stack as a primitive value.
316319 /// - Returns: The primitive value, or nil if not found.
320+ /// - Throws: When parsing the root fails.
317321 func currentElementAsSingleValue( ) throws -> URIParsedValue ? { try withCurrentPrimitiveElement { $0 } }
318322
319323 /// Returns the count of elements in the current top-of-stack array.
320324 /// - Returns: The number of elements.
325+ /// - Throws: When parsing the root fails.
321326 func countOfCurrentArray( ) throws -> Int { try withCurrentArrayElements { $0. count } }
322327
323328 /// Returns an element from the current top-of-stack array.
324329 /// - Parameter index: The position in the array to return.
325330 /// - Returns: The primitive value from the array.
331+ /// - Throws: When parsing the root fails.
326332 func nestedElementInCurrentArray( atIndex index: Int ) throws -> URIParsedValue {
327333 try withCurrentArrayElements { $0 [ index] }
328334 }
329335
330336 /// Returns an element from the current top-of-stack dictionary.
331337 /// - Parameter key: The key to find a value for.
332338 /// - Returns: The value for the key, or nil if not found.
339+ /// - Throws: When parsing the root fails.
333340 func nestedElementInCurrentDictionary( forKey key: String ) throws -> URIParsedValue ? {
334341 try withCurrentDictionaryElements { dictionary in try primitiveValue ( forKey: key, in: dictionary) }
335342 }
@@ -338,12 +345,14 @@ extension URIValueFromNodeDecoder {
338345 /// contains a value for the provided key.
339346 /// - Parameter key: The key for which to look for a value.
340347 /// - Returns: `true` if a value was found, `false` otherwise.
348+ /// - Throws: When parsing the root fails.
341349 func containsElementInCurrentDictionary( forKey key: String ) throws -> Bool {
342350 try withCurrentDictionaryElements { dictionary in dictionary [ key [ ... ] ] != nil }
343351 }
344352
345353 /// Returns a list of keys found in the current top-of-stack dictionary.
346354 /// - Returns: A list of keys from the dictionary.
355+ /// - Throws: When parsing the root fails.
347356 func elementKeysInCurrentDictionary( ) throws -> [ String ] {
348357 try withCurrentDictionaryElements { dictionary in dictionary. keys. map ( String . init) }
349358 }
0 commit comments