<@ULVA73B9P> What is the successor to the prefect....
# ask-marvin
j
@Marvin What is the successor to the prefect.engine.signals functionality/. Speficially, I am looking to fail a run if a custom exception is raised.
m
In Prefect 2.x, the functionality previously available through
prefect.engine.signals
in Prefect Core (1.x) has been replaced with new mechanisms. In Prefect 2.x, you don't need to use special signals to fail a flow run; instead, if a task raises any exception, the task is considered failed, and depending on how the flow is constructed, this can lead to the entire flow run failing. The system manages this natively, and you can see the error handling in the logs. To demonstrate how you can specifically handle a custom exception to fail a run, consider the following approach: 1. Define a custom exception in your code. 2. Raise this exception within a task when a specific condition is met. 3. The flow run will automatically handle this exception and mark the task run as failed. 4. Depending on the task's criticality and the flow's design, the whole flow run can be marked as failed. The excerpt from the documents doesn't directly mention the replacement of
prefect.engine.signals
, but you can extrapolate the lack of need for a direct successor from how exceptions are handled in the flow runs. If you use a custom exception, it will be caught just like any other exception, and task failure will be logged and propagated according to the flow's logic. If you want to manage Flow and Task states more granularly or programmatically, you might want to look into the state handling features offered by Prefect 2, such as setting up state handlers or using specific Prefect exceptions, like
FAIL
and
SKIP
. The Prefect 2.x documentation provides more details on handling custom logic for state transitions. Please note that direct excerpts specific to the old
prefect.engine.signals
system are not provided in my response since that feature has been replaced in Prefect 2.x with more comprehensive native error handling. If you need further clarification or examples, I would be happy to assist you.
n
👍 except
FAIL
and
SKIP
are not real, you can however return
Failed
state (
from prefect.states
) or give a
Completed
state a
name="SKIPPED"
to bookmark a completed state as skipped. but yeah tldr, just raise your own exceptions if you want, and
return
a state to force a final state determination
j
Thank you for correcting that.