Skip to content

Commit ce050bb

Browse files
authored
Merge pull request #1487 from cloudsufi/fem/action/GCSBucketDelete
[PLUGIN-1840] Error Management catch known errors [GCSBucketDelete]
2 parents a03238f + 5629eef commit ce050bb

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/main/java/io/cdap/plugin/gcp/gcs/actions/GCSBucketDelete.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
import io.cdap.cdap.api.annotation.Macro;
2626
import io.cdap.cdap.api.annotation.Name;
2727
import io.cdap.cdap.api.annotation.Plugin;
28+
import io.cdap.cdap.api.exception.ErrorType;
2829
import io.cdap.cdap.etl.api.FailureCollector;
2930
import io.cdap.cdap.etl.api.PipelineConfigurer;
3031
import io.cdap.cdap.etl.api.action.Action;
3132
import io.cdap.cdap.etl.api.action.ActionContext;
3233
import io.cdap.plugin.gcp.common.GCPConfig;
34+
import io.cdap.plugin.gcp.common.GCPErrorDetailsProviderUtil;
3335
import io.cdap.plugin.gcp.common.GCPUtils;
3436
import io.cdap.plugin.gcp.gcs.GCSPath;
3537
import org.apache.hadoop.conf.Configuration;
@@ -76,8 +78,17 @@ public void run(ActionContext context) throws Exception {
7678
return;
7779
}
7880
String serviceAccount = config.getServiceAccount();
79-
Credentials credentials = serviceAccount == null ?
80-
null : GCPUtils.loadServiceAccountCredentials(serviceAccount, isServiceAccountFilePath);
81+
Credentials credentials = null;
82+
try {
83+
credentials = serviceAccount == null ? null : GCPUtils.loadServiceAccountCredentials(serviceAccount,
84+
isServiceAccountFilePath);
85+
} catch (IOException e) {
86+
String errorReason = "Failed to load service account credentials. ";
87+
context.getFailureCollector()
88+
.addFailure(String.format("%s %s: %s", errorReason, e.getClass().getName(), e.getMessage()), null)
89+
.withStacktrace(e.getStackTrace());
90+
context.getFailureCollector().getOrThrowException();
91+
}
8192
Map<String, String> map = GCPUtils.generateGCSAuthProperties(serviceAccount, config.getServiceAccountType());
8293
map.forEach(configuration::set);
8394
configuration.set("fs.gs.impl", "com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem");
@@ -99,9 +110,9 @@ public void run(ActionContext context) throws Exception {
99110
storage.get(gcsPath.getBucket());
100111
} catch (StorageException e) {
101112
// Add more descriptive error message
102-
throw new RuntimeException(
103-
String.format("Unable to access or create bucket %s. ", gcsPath.getBucket())
104-
+ "Ensure you entered the correct bucket path and have permissions for it.", e);
113+
String errorReason = String.format("Unable to access GCS bucket '%s'", gcsPath.getBucket());
114+
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.UNKNOWN,
115+
true, GCPUtils.GCS_SUPPORTED_DOC_URL);
105116
}
106117
String exactGCSPath = "gs://" + gcsPath.getBucket() + "/" + gcsPath.getName();
107118
if (exactGCSPath.contains("*")) {

0 commit comments

Comments
 (0)