formula
formula copied to clipboard
Error handling during evaluation.
What
Creating a ticket to explore improvements to error handling within Formula. Currently, an error during evaluation can crash the whole feature which isn't great in production. While such issues aren't very common, I think we should provide APIs to contain the surface area of a crash.
The most common scenario is a duplicate key exception such as
val itemRenderModels = items.map { item ->
context.child(itemFormula, item)
}
One option to isolate such crashes is providing a special context.child API that has error handling built-in. This would be as such
// Returns a nullable render model instead of a real value in case of an error and fires `onError` callback.
val item: ItemRenderModel? = context.child(itemFormula, item) { error -> Log.e("ItemPage", error) }
How about we provide a custom lint rule that can be automatically integrated into Formula users' projects? Lint rule that detects key-less context.child() usage within the loop?
How about we provide a custom
lintrule that can be automatically integrated intoFormulausers' projects? Lint rule that detects key-lesscontext.child()usage within the loop?
I've been exploring lint rules a bit. Currently, I haven't figured out to have such a rule since the key() lives within the Formula. Also, it's hard to catch it if the loop is separated from context.child().