2525import io .cdap .cdap .api .annotation .Macro ;
2626import io .cdap .cdap .api .annotation .Name ;
2727import io .cdap .cdap .api .annotation .Plugin ;
28+ import io .cdap .cdap .api .exception .ErrorType ;
2829import io .cdap .cdap .etl .api .FailureCollector ;
2930import io .cdap .cdap .etl .api .PipelineConfigurer ;
3031import io .cdap .cdap .etl .api .action .Action ;
3132import io .cdap .cdap .etl .api .action .ActionContext ;
3233import io .cdap .plugin .gcp .common .GCPConfig ;
34+ import io .cdap .plugin .gcp .common .GCPErrorDetailsProviderUtil ;
3335import io .cdap .plugin .gcp .common .GCPUtils ;
3436import io .cdap .plugin .gcp .gcs .GCSPath ;
3537import 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