Skip to content

Weird way to handle errors in workflows #28638

@Barbapapazes

Description

@Barbapapazes

Existing documentation URL(s)

https://developers.cloudflare.com/workflows/build/sleeping-and-retrying/#catch-workflow-errors

What changes are you suggesting?

Hey 👋,

On the page "Sleeping and retrying", section "Catch Workflow Errors", there is something weird in the given example:

try {
    await step.do('non-retryable-task', async () => {
    // work not to be retried
        throw new NonRetryableError('oh no');
    });
} catch (e) {
    console.log(`Step failed: ${e.message}`);
    await step.do('clean-up-task', async () => {
      // Clean up code here
    });
}

Yes, this example works, but what happens if, instead of the NonRetryableError, a simple Error was thrown (like with a fetch)? The step clean-up-task is executed, and the workflow continues, but maybe I want to retry the workflow, so I re-throw the error. When the workflow will retry, and if it fails again, will the step clean-up-task run again?

Also, this is really weird to not have access to the number of retries of a step or a workflow (through the do callback for a step and event for the workflow).

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions