While working on the Apple Health import in BetterFit, I found that the same XML file could take two paths through the parser. Workouts already required finite, non-negative measurements. Top-level Record elements passed the raw attribute through Swift's Double initializer and stored the result. That allowed negative quantities and non-finite values into the daily summary, where a non-finite result could cause JSON encoding to fail.1
I routed numeric record values through the existing parser check. The record keeps its metadata and timestamps when the value is missing. A measured zero still counts, and a named sleep stage such as HKCategoryValueSleepAnalysisAsleepCore keeps its category and contributes duration. The regression tests add a bad sample before and after a valid one and check that totals, averages and the latest valid sample come out the same. They also check that a day with only invalid measurements still exports with its date and empty metric fields.1
The next morning, I added a check after workout unit conversion. An input like 1e308 hours passes the parser's finite check. Multiplying it by 3,600 produces infinity. Workout duration and distance now check the converted result before using it. An overflowing conversion leaves that measurement unavailable, so a distance lookup can still use another statistic or the workout total. Overflow while summing multiple workouts and conversions on top-level records remain open cases.2