mirror of
https://github.com/caoer/CodableFirebase.git
synced 2026-04-01 22:35:55 +08:00
If the value pushed a container before throwing, pop it back off to restore state
This commit is contained in:
@@ -393,11 +393,20 @@ extension _FirebaseEncoder {
|
||||
}
|
||||
|
||||
// The value should request a container from the _FirebaseEncoder.
|
||||
let depth = storage.count
|
||||
try value.encode(to: self)
|
||||
let depth = self.storage.count
|
||||
do {
|
||||
try value.encode(to: self)
|
||||
} catch {
|
||||
// If the value pushed a container before throwing, pop it back off to restore state.
|
||||
if self.storage.count > depth {
|
||||
let _ = self.storage.popContainer()
|
||||
}
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
// The top container should be a new container.
|
||||
guard storage.count > depth else {
|
||||
guard self.storage.count > depth else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user