specification: Add means to throw an error

What would you like to be added?

Add an action that allows throwing an error

Why is this needed?

Allows to define and throw workflow-specific errors, which is not possible as of now.

Coupled with the action’s condition property, it could provide users a very powerfull - yet extremely simple - tool to perform flow and/or data validation logic.

What is your proposal?

Create a new throw or error action type, that allows users to do the following:

actions:
  - name: is-room-available
    functionRef:
      refName: check-if-room-is-available
      arguments:
        id: 123
    actionDataFilter:
      toStateData: .roomAvailable
  - name: throw-if-not-true
    condition: ${ .roomAvailable == false }
    errorRef:
      refName: room-not-available

If, as suggested in #770, we get rid of the top-level errors property, then it could instead look like:

actions:
  - name: is-room-available
    functionRef:
      refName: check-if-room-is-available
      arguments:
        id: 123
    actionDataFilter:
      toStateData: .roomAvailable
  - name: throw-if-not-true
    condition: ${ .roomAvailable == false }
    throw:
      type: https://fake.hotel.com/errors/room-not-available
      status: 409
      title: Room Not Available

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 23 (15 by maintainers)

Most upvoted comments

And yes, a stack of errors will do too

@cdavernas yes, they are basically asking how to know (from the state that is executed when the error happen) which was the error that causes the transition. This allow the same state handling different error types or extract info from the error itself

So basically we nee a $WORKFLOW.lastError or something like that so users can do stuff like the one requested in those zulip discussion