swallow permalink

ignore pipeline step error permalink

If True, catch any errors raised by the step and continue to the next step. pypyr logs the error both the output and to runErrors in context, so you’ll know what happened, but processing continues. When you set swallow to True, pypyr will NOT go to the step-group’s failure handler.

You could think of this as on error resume next for your pipeline.

Defaults to False. This means by default pypyr will stop execution on a step error and quit reporting failure.

# ./swallow-decorator.yaml
steps:
  - name: pypyr.steps.assert
    comment: deliberately raise error
             step will swallow the error
             and proceed with pipeline.
    in:
      assert:
        this: False
    swallow: True
  - name: pypyr.steps.echo
    comment: this will run even though
             previous step raised exception
             because you swallowed the error.
    in:
      echoMe: You'll see me even though the previous step errored.

You can run this pipeline like this:

$ pypyr swallow-decorator
pypyr.steps.assert Ignoring error because swallow is True for this step.
pypyr.errors.ContextError: assert False evaluated to False.
You'll see me even though the previous step errored.

combining swallow & onError permalink

You can add custom error information to a step when you swallow by using the onError decorator.

# ./swallow-with-onerror.yaml
steps:
  - name: pypyr.steps.assert
    comment: deliberately raise error
             step will swallow the error
             and proceed with pipeline.
    in:
      assert:
        this: False
    onError: CUSTOM ERROR HERE
    swallow: True
  - name: pypyr.steps.echo
    comment: this will run even though
             previous step raised exception
             because you swallowed the error.
             the custom error is in runErrors.
    in:
        echoMe: "the error was: {runErrors[0][customError]}"

The output from this is:

$ pypyr swallow-with-onerror
pypyr.steps.assert Ignoring error because swallow is True for this step.
AssertionError: assert False evaluated to False.
the error was: CUSTOM ERROR HERE

see also

last updated on .