Acknowledged
over 1 year ago

getStressHistory crashing

Hi, good day to all.
I'm running the code below to get today's stress data:
var clockTime = Time.Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);
var midnight = new Time.Duration(clockTime.hour*3600 + clockTime.min*60 + clockTime.sec);
var stressIterator = SensorHistory.getStressHistory({ :period => midnight, :order => Sen.ORDER_OLDEST_FIRST});
It works fine and give me what I want almost always, however, when it's shortly after midnight (00:00, 00:01, etc) it crashes. The crash is at the third line of the above snippet, it says only:
Error: Invalid Value
Details: Failed invoking <symbol>
Notice that I'm simply requesting stress history and saving the return to a variable. At this point I'm not trying to access a property of "can be null" entity. This happens both in the simulator and physical device (Venu 2). To reproduce this error, I set the computer clock to 00:00:00 and run it.
Thanks in advance.
  • Yeah, I got around it by adding a if(secsFromMidnight < 600)[secsFromMidnight = 600;} and then using this secsFromMidnight inside theTime.Duration. But I wanted to know if this really is a bug, and if so, report it.

  • It should return a null in my opinion, but you can avoid the issue by making sure the duration isn't too short - a work around, but it could be some time before it's fixed as the 6.4.0 was just released.

  • If I change to 1000 it doesn't crash. But the point is: if I set a period shorter than the first sample, should it return null instead of crashing the whole app?

  • Sounds like the error is that parameters used to make the call.  For example, you are using the oldest first order, but only a duration of 10 seconds and history is saved far less often than every 10 seconds. If you change that 10 to 1000, does it crash?

    Your crash only happens right after midnight could be similar where the duration is too short.

    The way I'd do this is to use newest first and let the period be everything, and then use "when" in the sample to see when you've gotten what you want.

  • I said that the warnings are "local variable not used" only for you (or whoever joins us) to ignore them. The whole point is that even if I don't use the iterator for nothing, the app crashes.