https://prefect.io logo
Title
j

jpuris

02/28/2023, 6:39 PM
Heya! Is there a way to fail a flow intentionally without printing the stack trace of the failure?
if not is_success:
        logger.error(error_msg)
        return Failed(message="I've failed because ...!")
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

Nate

02/28/2023, 6:55 PM
you could pass
return_state=True
when calling your flow that returns
Failed
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

jpuris

02/28/2023, 6:57 PM
Thanks! I will try that 👍
👍 1
It works!! Thank you, @Nate 💯
:party-parrot: 2