Required nodes#
We’ve seen that the node’s default behavior in case of failure is to report and return None,
and the optional node gets completely ignored if it fails, but there is an opposite behavior
in case the node holds a mandatory operation; this is known as a required node.
A required node raises a FailureException [⮩]
in case of failure causing the whole process to stop instead of returning None,
this exception needs to be captured at the operation or application toplevel with a
Handler [⮩]
object, this follows the failures design.
This feature is mostly needed in nested nodes that are required (expected to success), either in chains or models, because there’s no way to mark a failure and break a chained operation other than raising an exception from inside.
But the exception (FailureException [⮩])
holds additional details like the source label and the input that caused that failure, and any application should wrap
those operations with the Handler [⮩]
to avoid breaking the entire application.
To demonstrate how can we mark a node as required, here’s a simple example
>>> from funchain import required, node