We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1384814 + 5b8627d commit 222b080Copy full SHA for 222b080
CodableFirebase/Encoder.swift
@@ -393,11 +393,20 @@ extension _FirebaseEncoder {
393
}
394
395
// The value should request a container from the _FirebaseEncoder.
396
- let depth = storage.count
397
- try value.encode(to: self)
+ let depth = self.storage.count
+ do {
398
+ try value.encode(to: self)
399
+ } catch {
400
+ // If the value pushed a container before throwing, pop it back off to restore state.
401
+ if self.storage.count > depth {
402
+ let _ = self.storage.popContainer()
403
+ }
404
+
405
+ throw error
406
407
408
// The top container should be a new container.
- guard storage.count > depth else {
409
+ guard self.storage.count > depth else {
410
return nil
411
412
0 commit comments