Contact Us 1-800-596-4880

Batch Errors

When a Mule app processes records through batch steps, record-level failures result in a BatchError object associated with the failed record. You can use DataWeave functions and selector expressions to inspect error details such as description, type, and stack trace. Starting with Mule 4.11, batch record errors replace exception-based tracking and wrap Mule error objects with enhanced error data.

Accessing Batch Errors

Within a batch step, you can access record errors using these DataWeave functions:

DataWeave Function Description

#[Batch::failureErrorForStep(String)]

Receives the name of a step as a String argument. Returns the BatchError object if the current record failed on that step. Otherwise, returns null.

#[Batch::getStepErrors()]

Returns a Map<String, BatchError> where keys are batch step names where the current record failed, and values are the corresponding errors.
If the record hasn’t failed in any step, returns an empty map (never null). The map doesn’t contain entries for steps in which the record hasn’t failed.

#[Batch::getFirstError()]

Returns the BatchError object for the first step in which the current record has failed. If the record hasn’t failed in any step, returns null.

#[Batch::getLastError()]

Returns the BatchError object for the last step in which the current record failed. Otherwise, returns null.

Selector Expressions for Batch Errors

Batch errors are complex data types with several fields, such as a description and type. When logging and handling batch errors, you can select values from any of these fields. This table shows selector expressions for the first step in which the current record failed:

Field Description Selector Expression

Description

A description of the problem.

#[Batch::getFirstError().description]

Detailed Description

A description of the problem, which can be the same or more extensive than the description field.

#[Batch::getFirstError().detailedDescription]

Type

A type that characterizes the problem and allows for routing within an error handler.

#[Batch::getFirstError().errorType]

Failing Component

The component where the error is generated.

#[Batch::getFirstError().failingComponent]

DSL Source

The DSL source of the component where the error is generated.

#[Batch::getFirstError().dslSource]

Error Message

An optional Mule message with error data (for example, HTTP response content for invalid status codes).

#[Batch::getFirstError().errorMessage]

Child Errors

An optional collection of inner errors, used by elements like Scatter-Gather to provide aggregated route errors.

#[Batch::getFirstError().childErrors]

Failure During Handling

Any error that occurs while handling this error.

#[Batch::getFirstError().failureDuringHandling]

Stack Trace

The Java stack trace of the exception.

#[Batch::getFirstError().stackTrace]

Batch Error Types

Batch errors follow the same error type hierarchy as standard Mule errors. A special MULE:BATCH error type exists for errors that arise during internal batch processing (rather than chain execution) and don’t belong to any specific type.