Skip to content

Add error details provider for Amazon S3 plugin #217

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

Open
wants to merge 1 commit into
base: develop
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
28 changes: 26 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-aws</artifactId>
<version>${hadoop.version}</version>
<exclusions>
<exclusion>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bundle</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
Expand All @@ -288,6 +299,11 @@
<artifactId>aws-java-sdk-sts</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>

<build>
Expand All @@ -310,7 +326,11 @@
<extensions>true</extensions>
<configuration>
<instructions>
<_exportcontents>io.cdap.plugin.aws.s3.*</_exportcontents>
<_exportcontents>
io.cdap.plugin.aws.s3.*;
org.apache.hadoop.fs.s3a.*;
org.apache.hadoop.fs.s3native.*;
</_exportcontents>
<Embed-Dependency>*;inline=false;scope=compile</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>lib</Embed-Directory>
Expand Down Expand Up @@ -492,7 +512,11 @@
<extensions>true</extensions>
<configuration>
<instructions>
<_exportcontents>io.cdap.plugin.aws.s3.*</_exportcontents>
<_exportcontents>
io.cdap.plugin.aws.s3.*;
org.apache.hadoop.fs.s3a.*;
org.apache.hadoop.fs.s3native.*;
</_exportcontents>
<Embed-Dependency>*;inline=false;scope=compile</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>lib</Embed-Directory>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright © 2025 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package io.cdap.plugin.aws.s3.common;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.model.AmazonS3Exception;
import com.google.common.base.Throwables;
import io.cdap.cdap.api.exception.ErrorCategory;
import io.cdap.cdap.api.exception.ErrorCodeType;
import io.cdap.cdap.api.exception.ErrorType;
import io.cdap.cdap.api.exception.ErrorUtils;
import io.cdap.cdap.api.exception.ErrorUtils.ActionErrorPair;
import io.cdap.cdap.api.exception.ProgramFailureException;
import io.cdap.cdap.etl.api.exception.ErrorContext;
import io.cdap.cdap.etl.api.exception.ErrorDetailsProvider;
import java.util.List;

/**
* Error details provided for the Amazon S3
**/
public final class AmazonErrorDetailsProvider implements ErrorDetailsProvider {

static final String S3_EXTERNAL_DOC =
"https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html";

@Override
public ProgramFailureException getExceptionDetails(Exception e, ErrorContext errorContext) {
List<Throwable> causalChain = Throwables.getCausalChain(e);
for (Throwable t : causalChain) {
if (t instanceof ProgramFailureException) {
// if causal chain already has program failure exception, return null to avoid double wrap.
return null;
}
if (t instanceof AmazonS3Exception) {
AmazonS3Exception amazonServiceException = (AmazonS3Exception) t;
int statusCode = amazonServiceException.getStatusCode();
ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(statusCode);
String errorReason = String.format("%s %s. %s. For more details, see %s", statusCode,
amazonServiceException.getErrorMessage(), pair.getCorrectiveAction(), S3_EXTERNAL_DOC);
return ErrorUtils.getProgramFailureException(new ErrorCategory(
ErrorCategory.ErrorCategoryEnum.PLUGIN, amazonServiceException.getErrorCode()),
errorReason, amazonServiceException.getMessage(), ErrorType.USER, true,
ErrorCodeType.HTTP, String.valueOf(statusCode), S3_EXTERNAL_DOC, t);
}
}
return null;
}
}
6 changes: 6 additions & 0 deletions src/main/java/io/cdap/plugin/aws/s3/sink/S3BatchSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.cdap.cdap.etl.api.batch.BatchSink;
import io.cdap.cdap.etl.api.batch.BatchSinkContext;
import io.cdap.cdap.etl.api.connector.Connector;
import io.cdap.plugin.aws.s3.common.AmazonErrorDetailsProvider;
import io.cdap.plugin.aws.s3.common.S3ConnectorConfig;
import io.cdap.plugin.aws.s3.common.S3Constants;
import io.cdap.plugin.aws.s3.common.S3Path;
Expand Down Expand Up @@ -87,6 +88,11 @@ protected LineageRecorder getLineageRecorder(BatchSinkContext context) {
return new LineageRecorder(context, asset);
}

@Override
protected String getErrorDetailsProviderClassName() {
return AmazonErrorDetailsProvider.class.getName();
}

@Override
protected Map<String, String> getFileSystemProperties(BatchSinkContext context) {
// when context is null, it is configure time, by that time, it will always use s3n
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/cdap/plugin/aws/s3/source/S3BatchSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.cdap.cdap.etl.api.batch.BatchSource;
import io.cdap.cdap.etl.api.batch.BatchSourceContext;
import io.cdap.cdap.etl.api.connector.Connector;
import io.cdap.plugin.aws.s3.common.AmazonErrorDetailsProvider;
import io.cdap.plugin.aws.s3.common.S3ConnectorConfig;
import io.cdap.plugin.aws.s3.common.S3Constants;
import io.cdap.plugin.aws.s3.common.S3EmptyInputFormat;
Expand Down Expand Up @@ -89,6 +90,11 @@ public void prepareRun(BatchSourceContext context) throws Exception {
super.prepareRun(context);
}

@Override
protected String getErrorDetailsProviderClassName() {
return AmazonErrorDetailsProvider.class.getName();
}

@Override
protected LineageRecorder getLineageRecorder(BatchSourceContext context) {
return new LineageRecorder(context, asset);
Expand Down