Skip to content

Commit

Permalink
feat(runtime): fail without retries on ConnectorInputException (#3844)
Browse files Browse the repository at this point in the history
* feat(runtime): fail without retries on ConncectorInputException

* skip retry for all ConnectorInputExceptions
  • Loading branch information
ztefanie authored Jan 15, 2025
1 parent dfd774f commit 348b88d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.camunda.client.api.worker.JobClient;
import io.camunda.client.api.worker.JobHandler;
import io.camunda.connector.api.error.ConnectorException;
import io.camunda.connector.api.error.ConnectorInputException;
import io.camunda.connector.api.error.ConnectorRetryException;
import io.camunda.connector.api.outbound.OutboundConnectorFunction;
import io.camunda.connector.api.secret.SecretProvider;
Expand Down Expand Up @@ -211,11 +212,18 @@ public void handle(final JobClient client, final ActivatedJob job) {
} catch (Exception ex) {
LOGGER.debug(
"Exception while processing job: {} for tenant: {}", job.getKey(), job.getTenantId(), ex);

String errorCode = null;
int retries = job.getRetries() - 1;

if (ex instanceof ConnectorException connectorException) {
errorCode = connectorException.getErrorCode();
}
result = handleSDKException(job, ex, job.getRetries() - 1, errorCode, retryBackoff);
if (ex instanceof ConnectorInputException
|| ex.getCause() instanceof ConnectorInputException) {
retries = 0;
}
result = handleSDKException(job, ex, retries, errorCode, retryBackoff);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.camunda.client.api.worker.JobClient;
import io.camunda.connector.api.error.ConnectorException;
import io.camunda.connector.api.error.ConnectorExceptionBuilder;
import io.camunda.connector.api.error.ConnectorInputException;
import io.camunda.connector.api.error.ConnectorRetryExceptionBuilder;
import io.camunda.connector.api.outbound.OutboundConnectorFunction;
import io.camunda.connector.runtime.core.ConnectorHelper;
Expand All @@ -46,13 +47,12 @@
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EmptySource;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.*;
import org.mockito.ArgumentCaptor;

class ConnectorJobHandlerTest {
Expand Down Expand Up @@ -506,6 +506,34 @@ void shouldTruncateBpmnErrorMessage() {
assertThat(result.getErrorMessage().length())
.isLessThanOrEqualTo(ConnectorJobHandler.MAX_ERROR_MESSAGE_LENGTH);
}

@ParameterizedTest
@MethodSource("provideInputExceptions")
void shouldNotRetry_OnConnectorInputException(Exception exception) {
// given
var jobHandler =
newConnectorJobHandler(
context -> {
throw exception;
});

// when
var result = JobBuilder.create().withRetries(3).executeAndCaptureResult(jobHandler, false);

// then
assertThat(result.getErrorMessage()).isEqualTo("expected Connector Input Exception");
assertThat(result.getRetries()).isEqualTo(0);
}

private static Stream<RuntimeException> provideInputExceptions() {
return Stream.of(
new ConnectorExceptionBuilder()
.message("expected Connector Input Exception")
.cause(new ConnectorInputException(new Exception()))
.build(),
new ConnectorInputException(
"expected Connector Input Exception", new RuntimeException("cause")));
}
}

@Nested
Expand Down Expand Up @@ -934,7 +962,7 @@ void shouldCreateBpmnError_UsingExceptionCodeAsFirstCondition() {
}

@Test
void shouldCreateJobErrpr_UsingExceptionCodeAsSecondConditionAfterResponseProperty()
void shouldCreateJobError_UsingExceptionCodeAsSecondConditionAfterResponseProperty()
throws JsonProcessingException {
// given
var errorExpression =
Expand Down

0 comments on commit 348b88d

Please sign in to comment.