Skip to content

Error management for Amazon S3 Source and Sink plugin #216

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
@@ -0,0 +1,56 @@
/*
* 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.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.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 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 s3Exception = (AmazonS3Exception) t;
String errorMessage = s3Exception.getErrorMessage();
String errorMessageWithDetails = s3Exception.getMessage();
return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
errorMessage, errorMessageWithDetails, ErrorType.USER, true, ErrorCodeType.HTTP, s3Exception.getErrorCode(),
S3_EXTERNAL_DOC, t);
}
}
return null;
}
}
12 changes: 10 additions & 2 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,8 @@
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.cdap.etl.api.exception.ErrorDetailsProviderSpec;
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 @@ -82,6 +84,11 @@ public void prepareRun(BatchSinkContext context) throws Exception {
super.prepareRun(context);
}

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

@Override
protected LineageRecorder getLineageRecorder(BatchSinkContext context) {
return new LineageRecorder(context, asset);
Expand Down Expand Up @@ -207,8 +214,9 @@ public void validate(FailureCollector collector) {
try {
getFilesystemProperties();
} catch (Exception e) {
collector.addFailure("File system properties must be a valid json.", null)
.withConfigProperty(NAME_FILE_SYSTEM_PROPERTIES).withStacktrace(e.getStackTrace());
collector.addFailure(String.format("File system properties must be a valid json, %s, %s",
e.getClass().getName(), e.getMessage()), null)
.withConfigProperty(NAME_FILE_SYSTEM_PROPERTIES).withStacktrace(e.getStackTrace());
}
}
}
Expand Down
12 changes: 10 additions & 2 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,8 @@
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.cdap.etl.api.exception.ErrorDetailsProviderSpec;
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 +91,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 Expand Up @@ -253,8 +260,9 @@ public void validate(FailureCollector collector) {
try {
getFilesystemProperties();
} catch (Exception e) {
collector.addFailure("File system properties must be a valid json.", null)
.withConfigProperty(NAME_FILE_SYSTEM_PROPERTIES).withStacktrace(e.getStackTrace());
collector.addFailure(String.format("File system properties must be a valid json, %s: %s",
e.getClass().getName(), e.getMessage()), null)
.withConfigProperty(NAME_FILE_SYSTEM_PROPERTIES).withStacktrace(e.getStackTrace());
}
}
}
Expand Down