Skip to content

Commit 57d9efc

Browse files
authored
Merge pull request #54 from Parsely/fix/guard-accumulators
Guard against using nonexistant accumulator values.
2 parents 6186f5b + 00fbd8f commit 57d9efc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ParselyTracker/EngagedTime.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class EngagedTime: Sampler {
4040
func endInteraction() {
4141
os_log("Ending Interaction", log: OSLog.tracker, type: .debug)
4242
for (url, _) in accumulators {
43+
guard var _ = accumulators[url] else {
44+
os_log("No accumulator found for %s, skipping endInteraction", log: OSLog.tracker, type:.debug, url)
45+
return
46+
}
4347
accumulators[url]!.isEngaged = false
4448
}
4549
}

ParselyTracker/Sampler.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ class Sampler {
139139
}
140140

141141
private func sendHeartbeat(key: String) -> Void {
142-
var trackedData = accumulators[key]!
142+
guard var trackedData = accumulators[key] else {
143+
os_log("No accumulator found for %s, skipping sendHeartbeat", log: OSLog.tracker, type:.debug, key)
144+
return
145+
}
143146
let incSecs: TimeInterval = trackedData.accumulatedTime
144147
if incSecs > 0 {
145148
os_log("Sending heartbeat for %s", log: OSLog.tracker, type:.debug, key)

0 commit comments

Comments
 (0)