Merge pull request #24 from alickbass/update-encoder

Update Encoder
This commit is contained in:
Oleksii Dykan
2018-02-20 23:11:31 +01:00
committed by GitHub

View File

@@ -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
}