Could someone point me to any examples of using `t...
# ask-community
s
Could someone point me to any examples of using
try ... catch
with Prefect 2 tasks, if it’s possible that is? I’d like to be able to skip a failed task and let downstream tasks proceed but it seems like a Failed task kills the entire flow. Or maybe I’m wrong?
a
I think you want allow_failure, but I think try/except also should work
z
Copy code
from prefect import task, flow, allow_failure


@task
def fail():
    raise ValueError()


@task
def succeed(x):
    return x


@flow
def example():
    try:
        fail()
    except ValueError:
        print("Ah it failed")

    print("All good!")

    state = fail(return_state=True)
    if state.is_failed():
        print("Ah it failed")

    print("All good")

    future = fail.submit()
    try:
        future.result()
    except ValueError:
        print("Ah it failed")

    print("All good!")

    return succeed(allow_failure(future))


example()
🔥 3
Here are a few examples 🙂
🙌 1
s
Thanks. Should this in theory work with
shell_run_command
?
z
Yep!
s
great