Closed samspycher closed 3 years ago
Looking at the code, the offending value is confirmed to be duration, and this exception will happen with any value lower than 15 minutes, because:
TempBasalExtraCommand
creates rateEntries of type RateEntry
with the static method RateEntry.createEntries
, createEntries
declares a remainingSegments int with
int remainingSegments = (int) Math.round(duration.getStandardSeconds() / 1800.0);
which puts this int at 0 for any duration less than 900s.while (remainingSegments > 0)
to actually create entries, leaving with 0 entries created in the case where remainingSegments
is already 0 and duration is less than 15m / 900s.TempBasalExtraCommand
then immediately calls the first non-existing entry, which results in the IndexOutOfBoundsException
I am not sure what to do here, because I am unaware of what the intent is for TBR durations.
@bartsopers thank you for your thoughts on this!
@samspycher good find! I'll have a look at it later this weekend as I currently don't have any access to a computer
I look at the code and I think this is a core issue: SmsCommunicatorPlugin
does not take PumpType.tbrSettings
into account, which I think it should.
I would suggest opening an issue for this in the main AAPS repo. Meanwhile, my proposal would be to validate the duration argument in two places:
RateEntry.createEntries()
: throw an IllegalArgumentException
when duration % 1800 != 0
to prevent the IndexOutOfBoundsException
OmnipodPumpPlugin.setTempBasalAbsolute
: also validate the duration here in a similar manner and return a PumpEnactResult
with a user friendly error message.@samspycher please let me know whether you agree with the proposed workaround. In case you are interested in fixing this yourself, I would be more than happy to review a PR. Otherwise I hope to be able to fix it later this week.
Fixed by @samspycher in AAPS core
When running on a basal of 0.2 IE/h, and setting this temporary basal via SMS:
BASAL 120% 10
The treatment will fail, showing this log output:
Contrasting this with an immediately following, succesful execution of the same TBR but for 20 minutes: