Skip to content

Failure

Each error caught in a step gives a Failure object, sent to the failures PCollection.

public class Failure implements Serializable {
private final String pipelineStep; // Name of the step
private final String inputElement; // Input element, as a string (toString)
private final Throwable exception; // Exception raised by the step
private final String originElement; // Element that entered the flow, null if not tracked (see Origin element)
private final Instant timestamp; // When the failure was created (since 1.3.0)
public static <T> Failure from(String pipelineStep, WithFailures.ExceptionElement<T> exceptionElement);
public static <T> Failure from(String pipelineStep, T element, Throwable exception);
// Computed from the exception (since 1.3.0), e.g. to write the failure to a dead letter queue.
public String getExceptionType(); // Class name, the original one for a SerializableThrowable
public String getExceptionMessage();
public String getStackTrace(); // Causes included
// Getters...
}

To write the failures to BigQuery or to add them to a Beam ErrorHandler, see Write the failures and Beam native error handling.

If the exception can’t be serialized, it’s replaced by a SerializableThrowable keeping the original class name, message, stack trace and causes (see Failure handling guarantees).

The input element is stored as a string:

  • Java: the toString() of the element.
  • Python: the JSON string of a dict (non JSON types like datetime or bytes converted with str), the str() of any other element.

To control the format, implement the string representation of your objects, e.g. as JSON:

public class Team implements Serializable {
// Fields...
@Override
public String toString() {
// Jackson is already a dependency of Beam.
return JsonUtil.serialize(this);
}
}