New in 0.16.2

v0.17.0

Workflow

Errors

Handling errors in a distributed system is typically complex. Infinitic simplifies this by automatically tracking error chains and allowing you to handle errors directly within the workflow.

Types of Exceptions in Workflows

The only exceptions that can be thrown inside a workflow are categorized as follows:

Due to Task failures

Due to Workflow Failures

All the exceptions mentioned above are derived from the DeferredException base class.

Errors Due to a Task Failure

TaskFailedException

This exception is thrown when a workflow attempts to access the result of a failed task. From a workflow point of view, a task is failed after all the automatic retries failed:

Error when a task fails

The TaskFailedException can also occur when waiting for the result of a task that was previously dispatched asynchronously:

Error when waiting for a failed task

If a task fails when dispatched asynchronously, it will not cause an exception within the workflow unless the workflow attempts to access the task's result.

failed task not awaited

A TaskFailedException has detailed information about the failed task:

PropertyTypeDescription
serviceNameStringThe name of the Service
taskIdStringThe ID of the failed task
methodNameStringThe name of the method called for the failed task
lastFailureTaskFailureDetails of the last failure

The TaskFailure object describes each attempt to execute the task and has the following properties:

PropertyTypeDescription
workerNameStringThe name of the worker where the exception occurred
exceptionGenericExceptionThe details of the original exception
stackTraceStringStringThe string version of the original exception
secondsBeforeRetrydouble?The duration in seconds before the next retry attempt - can be null if no retry
retryIndexIntegerThe number of retry attempts made before the current attempt
retrySequenceIntegerThe number of times the task was manually retried

The GenericException class is used to store the details of the original exception:

PropertyTypeDescription
nameStringThe name of the original exception
messageStringThe message of the original exception
causeGenericException?The cause of the original exception

The GenericException class provides two methods for accessing custom properties of the original exception:

  • the getCustomProperties() method returns a map containing all custom properties of the original exception.
  • the getCustomProperty(String name) method retrieves a specific custom property by its name, provided it was successfully serialized and deserialized.

When updating a Service Executor, be cautious about making changes to the name or type of custom properties associated with your exceptions. This could potentially disrupt running workflow instances that rely on these properties, as they might not be able to interpret messages containing the old name or type.

TaskTimedOutException

This exception is thrown when a workflow attempts to access the result of a timed-out task:

timed out task

A TaskTimedOutException has the following properties:

PropertyTypeDescription
serviceNameStringThe name of the Service
taskIdStringThe ID of the timed out task
methodNameStringThe name of the method called for the timed out task

Errors Due to a (Child) Workflow Failure

WorkflowFailedException

This exception is thrown when a workflow or a client attempts to access the result of another workflow that failed due to the failure of a task or another workflow.

For instance, this exception throws in the parent workflow of a failing child workflow:

Error in parent workflow when a workflow fails

Or if a client waits synchronously for the result of another failing workflow:

Error in client when a workflow fails

A WorkflowFailedException has the following properties:

PropertyTypeDescription
workflowNameStringThe name of the other workflow that failed
workflowIdStringThe unique identifier of the failed other workflow
workflowMethodNameStringThe name of the method that was called on the failed other workflow
workflowMethodIdStringThe unique identifier of the execution of the method that failed
deferredExceptionDeferredExceptionThe original exception that caused the other workflow to fail

WorkflowTimedOutException

This exception is thrown when a workflow or a client attempts to access the result of a child workflow that timed out. The timeout duration is specified in the interface of the Workflow:

timed out workflow

A WorkflowTimedOutException has the following properties:

PropertyTypeDescription
workflowNameStringThe name of the child workflow that timed out
workflowIdStringThe unique identifier of the timed out workflow instance
workflowMethodNameString?The name of the method that was called on the timed out child workflow
workflowMethodIdString?The unique identifier of the execution of the method that timed out

WorkflowCanceledException

This exception is thrown when a workflow or a client attempts to access the result of a child workflow that has been canceled.

A WorkflowCanceledException has the following properties:

PropertyTypeDescription
workflowNameStringThe name of the child workflow that timed out
workflowIdStringThe unique identifier of the timed out workflow instance
workflowMethodNameString?The name of the method that was called on the timed out child workflow
workflowMethodIdString?The unique identifier of the execution of the method that timed out

WorkflowUnknownException

This exception is thrown when a workflow or a client attempts to access the result of a child workflow that is unknown - this can happen when targeting a workflow by its ID.

A WorkflowCanceledException has the following properties:

PropertyTypeDescription
workflowNameStringThe name of the child workflow that timed out
workflowIdStringThe unique identifier of the timed out workflow instance
workflowMethodNameString?The name of the method that was called on the timed out child workflow
workflowMethodIdString?The unique identifier of the execution of the method that timed out

WorkflowExecutorException

This exception is thrown when a workflow or a client attempts to access the result of a workflow that failed due to an error in its own implementation.

A WorkflowExecutorException has the following properties:

PropertyTypeDescription
workflowNameStringThe name of the child workflow that failed
workflowIdStringThe unique identifier of the failed workflow instance
workflowTaskIdStringThe ID of the failed workflow execution
lastFailureTaskFailureDetails of the last failure

Try/catch in workflows

Use try/catch of DeferredException in workflows if you want to ensure that the workflow continues to run even if a task or another workflow failed:

Remember, for expected failures, it's a better practice to handle them within the Service and return a status object.

A DeferredException in a workflow cannot be resumed, as the workflow has already "moved on".

In workflows, do not catch any other exceptions then DeferredException. Specifically, actual exceptions thrown in Services or other workflows are wrapped within the DeferredException. It is not meaningful to try to catch these exceptions directly.

Previous
Deferred