Skip to content

Fix inverted condition on the max glucose count log - #73

Open
highflyer123 wants to merge 1 commit into
LoopKit:devfrom
highflyer123:fix/glucose-max-count-log-condition
Open

Fix inverted condition on the max glucose count log#73
highflyer123 wants to merge 1 commit into
LoopKit:devfrom
highflyer123:fix/glucose-max-count-log-condition

Conversation

@highflyer123

@highflyer123 highflyer123 commented Aug 25, 2026

Copy link
Copy Markdown

The change

-        if result.count < maxFetchCount() {
+        if result.count >= maxFetchCount() {
             print("Hit max glucose count: Consider increasing")
         }

Why

The condition was inverted in 6698b30 ("Remove assertion"), which rewrote

assert(result.count < maxFetchCount(), "Hit max count: Consider increasing")

as

if result.count < maxFetchCount() { print("Hit max glucose count: Consider increasing") }

assert fires when its condition is violated; the if fires when it holds.

result.count can never exceed maxFetchCount()
fetchGlucose(dateInterval:maxCount:) passes maxCount through as Nightscout's
count= query parameter, and everything after it (compactMap into
[GlucoseEntry], then a 1:1 toGlucoseSample()) can only shrink the array. So
the warning prints on every successful fetch and stays silent in exactly the
case it exists to report — a fetch truncated at the cap.

>= rather than == so it still reports a server that ignores count=.
Diagnostic only — result is returned unchanged.

Testing

Built and tested against dev (fc86735), Xcode 26.2, iOS 26.2 simulator:
LoopCaregiverKit and the LoopCaregiver app scheme build clean, and
LoopCaregiverKitTests passes (9 tests, 0 failures).

The check was mechanically inverted in 6698b30 when

    assert(result.count < maxFetchCount(), "Hit max count: Consider increasing")

became

    if result.count < maxFetchCount() { print("Hit max glucose count: Consider increasing") }

The assert fired when its condition was violated; the `if` fires when the
same condition holds, so the meaning is reversed.

NightscoutKit passes `maxCount` straight through as Nightscout's `count=`
query parameter, so `result.count` can never exceed `maxFetchCount()`.
That makes the current condition true on every successful fetch and false
in exactly the one case it exists to report — a fetch truncated at the
limit. Inverting it to `>=` restores the original intent.
@highflyer123
highflyer123 force-pushed the fix/glucose-max-count-log-condition branch from 252fc13 to db88f76 Compare August 25, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant