Gregorian.info - is it null safe or anything else to consider if used?

I have following code:

var infoShort = Gregorian.info(Time.now(), Time.FORMAT_SHORT);
var day = infoShort.day;
var dayOfWeek = infoShort.day_of_week; // 1 = Sunday, 2 = Monday, ..., 7 = Saturday
var month = infoShort.month; //1 = January, 2= February, ..., 12 = December
var year = infoShort.year;

I get same Invalid value and System error crashes when using the data above... E.g. I see 160 Invalid value crash errors for following line:

var resDays = [
	Rez.Strings.Sun,
	Rez.Strings.Mon,
	Rez.Strings.Tue,
	Rez.Strings.Wed,
	Rez.Strings.Thu,
	Rez.Strings.Fri,
	Rez.Strings.Sat
];
var weekdayName = WatchUi.loadResource(resDays[dayOfWeek - 1]); // <= crashes sometimes

I think assuming that dayOfWeek is in the range [1, 7] as documented here (https://developer.garmin.com/connect-iq/api-docs/Toybox/Time/Gregorian.html) should be save, but why do I get the above exception then?

  • Again, as I said in the other thread, a simple println would show you what's happening.

    for example, is dayOfWeek always set when you do the var weekdayName?

  • hi,

    be sure you have the strings "sun","Mon" etc in every xml string ressource

  • If I can't reproduce this and it runs on the emulator / my device / 99% of all users without problems, how can printlns help here? If I would have an idea on what I could try out, I would try it with printlns of course, but I'm stuck with the error message only...

    I do get this error for many languages and many devices and I'm sure I don't have missed any string in any language - I've a small translateable string file that I copy and paste into all languages and I checked it again. I even get this error on the same device as I own - but I don't see this problem on my device.

    It looks like I miss some basic state that I do not think of that must be true so that this error occurs

    for example, is dayOfWeek always set when you do the var weekdayName?

    it is in the emulator and it is for sure in all cases, as the code above is the full code that leads to this issue.

  • If real users see this, check your ERA logs, as you'll see an easy to understand stack trace.

  • It's too bad that release-mode runtime assertions aren't supported. Then we could have assertions with custom strings which show up in the error reporting messages -- e.g. you could print out the value of dayOfWeek (if it's not a number between 1 and 7) and receive it in the ERA message.

    Because sometimes "System Error" and "Invalid Value" are all you get.

  • The stacktrace is what leads to my question... There's not more information in the stacktrace but the obvious one (the calling stack). As FlowState says, having a way to add checks at runtime with assertions would be really helpful - I would know which checks I would add and then I could check ERA again

    Currently I can assume something (like dayOfWeek not in range [1, 7]) and show an error to the user - but adding such logic for every problem I assume could be there would increase code base (assertions would as well) and I would need to wait until a user writes me and asks me what the error means (assertions could work in ERA without user interaction)

  • If the ERAs only show a few languages, maybe try those on your watch.  

  • thanks. that's something I have considered and I tried all languages without "success" - it happens for many languages, so this seems not to be a precondition for my problem

  • If it was Gregorian.Info, others would be seeing it.  I map the short DOW to a string in any that use a custom font with date for example.

    is it by any chance something that only happens on Sunday (for example) you may have to run for a few days.

  • is it by any chance something that only happens on Sunday (for example) you may have to run for a few days.

    I thought about that as well - I tried to test if first day of week does have an influence, but it seems, it doesn't. Also I tried to change my system time to fri, sat, sun, mon and this all works in the sim (it also works on my own watch where I use my watchface everyday).

    I map the short DOW to a string in any that use a custom font with date for example.

    DOW = day of week? You map the localised week names?