Skip to content

Commit 1f3befa

Browse files
authored
[FirebaseCore] Use optional instead of error (#10906)
* [FirebaseCore] Use optional instead of error * Revert debugging change * Fix typo
1 parent c0e6ac1 commit 1f3befa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatStorage.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,16 @@ final class HeartbeatStorage: HeartbeatStorageProtocol {
134134

135135
/// Loads and decodes the stored heartbeats bundle from a given storage object.
136136
/// - Parameter storage: The storage container to read from.
137-
/// - Returns: The decoded `HeartbeatsBundle` that is loaded from storage.
138-
private func load(from storage: Storage) throws -> HeartbeatsBundle {
137+
/// - Returns: The decoded `HeartbeatsBundle` loaded from storage; `nil` if storage is empty.
138+
/// - Throws: An error if storage could not be read or the data could not be decoded.
139+
private func load(from storage: Storage) throws -> HeartbeatsBundle? {
139140
let data = try storage.read()
140-
let heartbeatData = try data.decoded(using: decoder) as HeartbeatsBundle
141-
return heartbeatData
141+
if data.isEmpty {
142+
return nil
143+
} else {
144+
let heartbeatData = try data.decoded(using: decoder) as HeartbeatsBundle
145+
return heartbeatData
146+
}
142147
}
143148

144149
/// Saves the encoding of the given value to the given storage container.

0 commit comments

Comments
 (0)