Conversation
Treatment parsers force-cast `timestamp`/`created_at` to String after a `!= nil` check. A treatment carrying a JSON null or numeric timestamp passes the nil check and traps in swift_dynamicCast on the main queue, so the app aborts on every launch while that record is within the download window. Add NightscoutUtils.treatmentDate(from:) which accepts ISO 8601 strings, epoch milliseconds/seconds, and falls back to created_at on null; use it in the bolus, SMB, carb, note and stats parsers. Replace the remaining forced casts in device status, SAge, CAge and IAge handling with conditional binding so malformed data is skipped instead of crashing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
zersoft
requested review from
bjorkert,
codebymini and
marionbarker
as code owners
September 26, 2026 20:47
Author
|
Real-device confirmation: the TestFlight build with this fix (fork build of 7.1.0) launches and runs normally on the Mac and Nightscout instance that reproduced the crash on every launch before. No further crashes observed. |
bjorkert
approved these changes
Sep 27, 2026
bjorkert
left a comment
Member
There was a problem hiding this comment.
LGTM, Thanks for your contribution!
zersoft
added a commit
to zerloop/LoopFollow
that referenced
this pull request
Sep 27, 2026
… yet in upstream dev)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Loop Follow 7.1.0 (60) aborts on every launch when Nightscout returns a treatment whose
timestampfield is present but not a string (JSONnullor an epoch number). The bolus/SMB/carb/note/stats parsers check!= niland thenas! String, soNSNullorNSNumberpasses the nil check and traps inswift_dynamicCaston the main queue. The crash repeats on every launch as long as the record is inside the download window.Crash signature (macOS 27, Designed for iPad build, also reproducible on iOS):
Changes
NightscoutUtils.treatmentDate(from:): usestimestamp, falls back tocreated_at, accepts ISO 8601 strings and epoch milliseconds/seconds, returnsnil(entry skipped) for anything else.Treatments/Bolus.swift,SMB.swift,Carbs.swift,Notes.swiftand the three parsers inStats/StatsDataFetcher.swift, replacing the forced casts.recommendedTempBasal.timestampinDeviceStatusLoop/DeviceStatusOpenAPS,predicted.values/prediction.last!inDeviceStatusLoop, andas! TimeInterval/as! StringinSAge,CAge,IAge.Testing
Tests/NightscoutTreatmentDateTests.swift(5 cases: string,created_atfallback,nullfallback, numeric ms/s, unsupported values → nil).Teststarget: 102 passed, 0 failed (iOS 27 simulator).--lintclean.🤖 Generated with Claude Code