Search in sources :

Example 1 with TemporalFailure

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);
}
Also used : ChildWorkflowFailure(io.temporal.failure.ChildWorkflowFailure) CanceledFailure(io.temporal.failure.CanceledFailure) WorkflowException(io.temporal.client.WorkflowException) ChildWorkflowTaskFailedException(io.temporal.internal.replay.ChildWorkflowTaskFailedException) TemporalFailure(io.temporal.failure.TemporalFailure)

Example 2 with TemporalFailure

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);
}
Also used : WorkflowExecutionException(io.temporal.internal.worker.WorkflowExecutionException) TemporalFailure(io.temporal.failure.TemporalFailure) Failure(io.temporal.api.failure.v1.Failure) TemporalFailure(io.temporal.failure.TemporalFailure)

Example 3 with TemporalFailure

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);
}
Also used : FailureWrapperException(io.temporal.internal.replay.FailureWrapperException) Scope(com.uber.m3.tally.Scope) TimeoutFailure(io.temporal.failure.TimeoutFailure) SimulatedTimeoutFailure(io.temporal.failure.SimulatedTimeoutFailure) ActivityCanceledException(io.temporal.client.ActivityCanceledException) TemporalFailure(io.temporal.failure.TemporalFailure) SimulatedTimeoutFailure(io.temporal.failure.SimulatedTimeoutFailure) TimeoutFailure(io.temporal.failure.TimeoutFailure) TemporalFailure(io.temporal.failure.TemporalFailure) SimulatedTimeoutFailure(io.temporal.failure.SimulatedTimeoutFailure) Failure(io.temporal.api.failure.v1.Failure) RespondActivityTaskFailedRequest(io.temporal.api.workflowservice.v1.RespondActivityTaskFailedRequest)

Example 4 with TemporalFailure

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);
}
Also used : WorkflowExecutionException(io.temporal.internal.worker.WorkflowExecutionException) TemporalFailure(io.temporal.failure.TemporalFailure) CanceledFailure(io.temporal.failure.CanceledFailure) TemporalFailure(io.temporal.failure.TemporalFailure) Failure(io.temporal.api.failure.v1.Failure)

Aggregations

TemporalFailure (io.temporal.failure.TemporalFailure)4 Failure (io.temporal.api.failure.v1.Failure)3 CanceledFailure (io.temporal.failure.CanceledFailure)2 WorkflowExecutionException (io.temporal.internal.worker.WorkflowExecutionException)2 Scope (com.uber.m3.tally.Scope)1 RespondActivityTaskFailedRequest (io.temporal.api.workflowservice.v1.RespondActivityTaskFailedRequest)1 ActivityCanceledException (io.temporal.client.ActivityCanceledException)1 WorkflowException (io.temporal.client.WorkflowException)1 ChildWorkflowFailure (io.temporal.failure.ChildWorkflowFailure)1 SimulatedTimeoutFailure (io.temporal.failure.SimulatedTimeoutFailure)1 TimeoutFailure (io.temporal.failure.TimeoutFailure)1 ChildWorkflowTaskFailedException (io.temporal.internal.replay.ChildWorkflowTaskFailedException)1 FailureWrapperException (io.temporal.internal.replay.FailureWrapperException)1