Error handling in CommCare Apps

Hi,

Just wondering if there's anyone here that has a way of handling unexpected errors. like an error handler/catcher bit of code that will allow your forms to move on if something unexpected happens. cause otherwise, we should consider asking the wonderful folks at Dimagi for one.

For example, i'm referencing location types for form display conditions, and if i log in to the app with a web-user on the emulator online, it throws an error. it only works for mobile workers.

this is fine. i was just hoping to find creative ways to handle run-time errors. like, an iferror function or something -> IfError(expressions,value if error is encountered)

Mazz

Hi Mazz,

You may find the "Login As" Feature helpful for testing apps which rely on user or fixture data in their structure.

It's also the case that the if() function as well as the AND and OR operations do "short-circuit", logically, meaning that if a part of the expression isn't relevant in the current context, it won't be evaluated. So,

if( 1 == 2, cause_error(), true()) OR cause_error()

won't ever cause issues. It's important to write this logic carefully, though, such that the 'default' path is the one with no error.

I do agree that something similar to Excel's "IFERROR()" could be generally helpful, although we try to generally follow the standards for XForms and XPath that back our tools so as to not introduce elements that would make our forms noncompliant. In cases like these if you are making a suggestion to the team, it's helpful to review whether an existing XPath mechanism exists that can be proposed for implementation.

-Clayton

Thanks Clayton,

I'll make sure to double check next time. Valid points indeed

Mazz

No problem, and you can suggest features with our without an existing spec to implement, it's just very helpful for the team to know when there is an existing mechanism since it would be our first point of investigation.

-Clayton