formula icon indicating copy to clipboard operation
formula copied to clipboard

Error handling during evaluation.

Open Laimiux opened this issue 4 years ago • 2 comments

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) }

Laimiux avatar Sep 10 '21 22:09 Laimiux

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?

alexanderbezverhni avatar Sep 13 '21 02:09 alexanderbezverhni

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?

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().

Laimiux avatar Sep 13 '21 16:09 Laimiux