Don’t trap exceptions in try/except blocks and don’t raise the FAIL
signal explicitly - as long as the exception remains unhandled, the flow run will fail and the error will be logged with the ERROR log level:
from prefect import task, Flow
@task
def fail_successfully(x):
return 1 / x
with Flow(name="fail") as flow:
result = fail_successfully(x=0)
Raising signals logs the errors with INFO log level rather than ERROR log level
from prefect import task, Flow
from prefect.engine.signals import FAIL
@task
def fail_successfully(x):
if x == 0:
raise FAIL(message="Division by zero!")
return 1 / x
with Flow(name="fail") as flow:
result = fail_successfully(x=0)