25
25
import io .cdap .cdap .api .annotation .Macro ;
26
26
import io .cdap .cdap .api .annotation .Name ;
27
27
import io .cdap .cdap .api .annotation .Plugin ;
28
+ import io .cdap .cdap .api .exception .ErrorType ;
28
29
import io .cdap .cdap .etl .api .FailureCollector ;
29
30
import io .cdap .cdap .etl .api .PipelineConfigurer ;
30
31
import io .cdap .cdap .etl .api .action .Action ;
31
32
import io .cdap .cdap .etl .api .action .ActionContext ;
32
33
import io .cdap .plugin .gcp .common .GCPConfig ;
34
+ import io .cdap .plugin .gcp .common .GCPErrorDetailsProviderUtil ;
33
35
import io .cdap .plugin .gcp .common .GCPUtils ;
34
36
import io .cdap .plugin .gcp .gcs .GCSPath ;
35
37
import org .apache .hadoop .conf .Configuration ;
@@ -76,8 +78,17 @@ public void run(ActionContext context) throws Exception {
76
78
return ;
77
79
}
78
80
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
+ }
81
92
Map <String , String > map = GCPUtils .generateGCSAuthProperties (serviceAccount , config .getServiceAccountType ());
82
93
map .forEach (configuration ::set );
83
94
configuration .set ("fs.gs.impl" , "com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem" );
@@ -99,9 +110,9 @@ public void run(ActionContext context) throws Exception {
99
110
storage .get (gcsPath .getBucket ());
100
111
} catch (StorageException e ) {
101
112
// 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 );
105
116
}
106
117
String exactGCSPath = "gs://" + gcsPath .getBucket () + "/" + gcsPath .getName ();
107
118
if (exactGCSPath .contains ("*" )) {
0 commit comments