Within my JavaScript code, I have a complex predicate that comprises of multiple tests chained together against a value.
I am looking for a way to log the specific location in the expression where it fails, if it does fail. Similar to how testing libraries provide error logs indicating where an exception occurred.
Is there any form of reflection or introspection available that can help me extract a descriptive explanation of what caused the expression to fail?
For example:
const predicate = a.foo == 1 && a.bar < 3 && someOtherPredicate(a.bar)
// If predicate evaluates to false, console.log ->
// "error: b.bar < 3 evaluated to false"
(I specifically want to achieve this in TypeScript, but I am open to exploring features in JavaScript that could facilitate this)