Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtime): fail without retries on ConnectorInputException #3844

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
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 @@ -35,6 +35,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
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 @@ -47,13 +48,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 @@ -507,6 +507,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 @@ -935,7 +963,7 @@ void shouldCreateBpmnError_UsingExceptionCodeAsFirstCondition() {
}

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