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 1 commit
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 @@ -212,10 +213,15 @@ public void handle(final JobClient client, final ActivatedJob job) {
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();
Throwable cause = connectorException.getCause();
if (cause instanceof ConnectorInputException) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe check if ex instanceof ConnectorInputException because currently your test might if I replace jobHandler by :

     var jobHandler =
          newConnectorJobHandler(
              context -> {
                throw new ConnectorInputException(
                    "expected Connector Input Exception", new RuntimeException("cause"));
              });

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because one can create the exception using new ConnectorInputException.. or using the builder, and it will lead to different exceptions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍 Thanks for mentioning and explaining. I adjusted it and added it to the tests.

retries = 0;
}
}
result = handleSDKException(job, ex, job.getRetries() - 1, errorCode, retryBackoff);
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 Down Expand Up @@ -507,6 +508,26 @@ void shouldTruncateBpmnErrorMessage() {
assertThat(result.getErrorMessage().length())
.isLessThanOrEqualTo(ConnectorJobHandler.MAX_ERROR_MESSAGE_LENGTH);
}

@Test
void shouldNotRetry_OnConnectorInputException() {
// given
var jobHandler =
newConnectorJobHandler(
context -> {
throw new ConnectorExceptionBuilder()
.message("expected Connector Input Exception")
.cause(new ConnectorInputException(new Exception()))
.build();
});

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

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

@Nested
Expand Down Expand Up @@ -935,7 +956,7 @@ void shouldCreateBpmnError_UsingExceptionCodeAsFirstCondition() {
}

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