Heya! Is there a way to fail a flow intentionally ...
# ask-community
j
Heya! Is there a way to fail a flow intentionally without printing the stack trace of the failure?
Copy code
if not is_success:
        logger.error(error_msg)
        return Failed(message="I've failed because ...!")
Copy code
19:31:34.931 | ERROR   | Flow run 'sociable-mantis' - Traceback (most recent call last):
  ... actually relevant stack trace from "error_msg" ...

19:31:35.161 | ERROR   | Flow run 'sociable-mantis' - Finished in state Failed('I've failed because ...!')
Traceback (most recent call last):
<... a massive stack trace on raising a failure from prefect :(>
    raise await get_state_exception(state)
prefect.exceptions.FailedRun: I've failed because ...!
The last stack trace is really unnecessary. I'd only want to output information that the flow has ended in failure state 😞
1
n
you could pass
return_state=True
when calling your flow that returns
Failed
Copy code
In [8]: @flow
   ...: def testing():
   ...:     return Failed(message="i dont want a stack trace")
   ...:

In [9]: testing(return_state=True)

10:54:21.538 | INFO    | prefect.engine - Created flow run 'pristine-cuttlefish' for flow 'testing'

10:54:23.156 | ERROR   | Flow run 'pristine-cuttlefish' - Finished in state Failed('i dont want a stack trace')
Out[9]: Failed(message='i dont want a stack trace', type=FAILED, result=LiteralResult(type='literal', artifact_type='result', artifact_description='Literal: `None`', value=None))
j
Thanks! I will try that 👍
👍 1
It works!! Thank you, @Nate 💯
🦜 2