use of io.temporal.failure.TemporalFailure in project sdk-java by temporalio.
the class SyncWorkflowContext method mapChildWorkflowException.
private RuntimeException mapChildWorkflowException(Exception failure) {
if (failure == null) {
return null;
}
if (failure instanceof TemporalFailure) {
((TemporalFailure) failure).setDataConverter(getDataConverter());
}
if (failure instanceof CanceledFailure) {
return (CanceledFailure) failure;
}
if (failure instanceof WorkflowException) {
return (RuntimeException) failure;
}
if (failure instanceof ChildWorkflowFailure) {
return (ChildWorkflowFailure) failure;
}
if (!(failure instanceof ChildWorkflowTaskFailedException)) {
return new IllegalArgumentException("Unexpected exception type: ", failure);
}
ChildWorkflowTaskFailedException taskFailed = (ChildWorkflowTaskFailedException) failure;
Throwable cause = FailureConverter.failureToException(taskFailed.getFailure(), getDataConverter());
// To support WorkflowExecutionAlreadyStarted set at handleStartChildWorkflowExecutionFailed
if (cause == null) {
cause = failure.getCause();
}
return new ChildWorkflowFailure(0, 0, taskFailed.getWorkflowType().getName(), taskFailed.getWorkflowExecution(), null, taskFailed.getRetryState(), cause);
}
use of io.temporal.failure.TemporalFailure in project sdk-java by temporalio.
the class WorkflowExecuteRunnable method mapToWorkflowExecutionException.
static WorkflowExecutionException mapToWorkflowExecutionException(Throwable exception, DataConverter dataConverter) {
Throwable e = exception;
while (e != null) {
if (e instanceof TemporalFailure) {
((TemporalFailure) e).setDataConverter(dataConverter);
}
e = e.getCause();
}
Failure failure = FailureConverter.exceptionToFailure(exception);
return new WorkflowExecutionException(failure);
}
use of io.temporal.failure.TemporalFailure in project sdk-java by temporalio.
the class POJOActivityTaskHandler method mapToActivityFailure.
@SuppressWarnings("deprecation")
private ActivityTaskHandler.Result mapToActivityFailure(Throwable exception, String activityId, Scope metricsScope, boolean isLocalActivity) {
if (exception instanceof ActivityCanceledException) {
if (isLocalActivity) {
metricsScope.counter(MetricsType.LOCAL_ACTIVITY_EXEC_CANCELLED_COUNTER).inc(1);
metricsScope.counter(MetricsType.LOCAL_ACTIVITY_CANCELED_COUNTER).inc(1);
} else {
metricsScope.counter(MetricsType.ACTIVITY_EXEC_CANCELLED_COUNTER).inc(1);
metricsScope.counter(MetricsType.ACTIVITY_CANCELED_COUNTER).inc(1);
}
String stackTrace = FailureConverter.serializeStackTrace(exception);
throw new FailureWrapperException(Failure.newBuilder().setStackTrace(stackTrace).setCanceledFailureInfo(CanceledFailureInfo.newBuilder()).build());
}
Scope ms = metricsScope.tagged(ImmutableMap.of(MetricsTag.EXCEPTION, exception.getClass().getSimpleName()));
if (isLocalActivity) {
ms.counter(MetricsType.LOCAL_ACTIVITY_EXEC_FAILED_COUNTER).inc(1);
ms.counter(MetricsType.LOCAL_ACTIVITY_FAILED_COUNTER).inc(1);
} else {
ms.counter(MetricsType.ACTIVITY_EXEC_FAILED_COUNTER).inc(1);
}
if (exception instanceof TemporalFailure) {
((TemporalFailure) exception).setDataConverter(dataConverter);
}
if (exception instanceof TimeoutFailure) {
exception = new SimulatedTimeoutFailure((TimeoutFailure) exception);
}
Failure failure = FailureConverter.exceptionToFailure(exception);
RespondActivityTaskFailedRequest.Builder result = RespondActivityTaskFailedRequest.newBuilder().setFailure(failure);
return new ActivityTaskHandler.Result(activityId, null, new Result.TaskFailedResult(result.build(), exception), null, null, false);
}
use of io.temporal.failure.TemporalFailure in project sdk-java by temporalio.
the class POJOWorkflowImplementationFactory method mapToWorkflowExecutionException.
static WorkflowExecutionException mapToWorkflowExecutionException(Throwable exception, DataConverter dataConverter) {
Throwable e = exception;
while (e != null) {
if (e instanceof TemporalFailure) {
((TemporalFailure) e).setDataConverter(dataConverter);
}
e = e.getCause();
}
Failure failure = FailureConverter.exceptionToFailure(exception);
return new WorkflowExecutionException(failure);
}
Aggregations