Christian Juhl
09/27/2022, 3:34 PMfrom prefect import flow, task, get_run_logger
from prefect.orion.schemas.states import Failed
def my_function():
raise Exception('This is an exception')
@flow
def run_flow():
logger = get_run_logger()
try:
result = my_function()
<http://logger.info|logger.info>(result)
except Exception as e:
errmsg = f"Error! Type: {e.__class__.__name__} Detail: {e}"
logger.error(errmsg)
return Failed()
if __name__ == "__main__":
run_flow()
However, I get the following error;
Exception has occurred: TypeError
Unexpected result for failure state: None —— NoneType cannot be resolved into an exception
File "main.py", line 21, in <module>
run_flow()
I'm thinking I might be doing more than one thing wrong here. Can anyone enlighten me, please? Thanks!Christopher Boyd
09/27/2022, 4:01 PMresult = my_function()
but my_function()
has no return, which is presumably then None
Khuyen Tran
09/27/2022, 4:02 PMreturn Failed()
Christian Juhl
09/28/2022, 2:01 PMfrom prefect import flow, task, get_run_logger
from prefect.orion.schemas.states import Failed
@task
def my_function():
return 1
@flow
def run_flow():
logger = get_run_logger()
try:
result = my_function()
<http://logger.info|logger.info>(result)
raise Exception('This is an exception')
except Exception as e:
errmsg = f"Error! Type: {e.__class__.__name__} Detail: {e}"
logger.error(errmsg)
return Failed()
if __name__ == "__main__":
run_flow()
Thanks @Khuyen Tran, I realize that returning the Failed state is causing the error, but I don't know how else I would get my flow to finish in Failed state.Christopher Boyd
09/28/2022, 2:23 PMChristian Juhl
10/04/2022, 3:25 PMif y.result() == "success":
to if y.result() != "success":
it will throw the same exception:
Exception has occurred: TypeError
Unexpected result for failure state: None —— NoneType cannot be resolved into an exceptionChristopher Boyd
10/04/2022, 4:04 PM