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 .ErrorCategory ;
29+ import io .cdap .cdap .api .exception .ErrorType ;
30+ import io .cdap .cdap .api .exception .ErrorUtils ;
2831import io .cdap .cdap .etl .api .FailureCollector ;
2932import io .cdap .cdap .etl .api .PipelineConfigurer ;
3033import io .cdap .cdap .etl .api .action .Action ;
@@ -76,8 +79,16 @@ public void run(ActionContext context) throws Exception {
7679 return ;
7780 }
7881 String serviceAccount = config .getServiceAccount ();
79- Credentials credentials = serviceAccount == null ?
80- null : GCPUtils .loadServiceAccountCredentials (serviceAccount , isServiceAccountFilePath );
82+ Credentials credentials = null ;
83+ try {
84+ credentials = serviceAccount == null ? null : GCPUtils .loadServiceAccountCredentials (serviceAccount ,
85+ isServiceAccountFilePath );
86+ } catch (IOException e ) {
87+ String errorReason = "Failed to load service account credentials. " ;
88+ context .getFailureCollector ().addFailure (String .format ("%s %s" , errorReason , 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,11 @@ 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 or create bucket %s. " , gcsPath .getBucket ()) +
114+ "Ensure you entered the correct bucket path and have permissions for it." ;
115+ String errorMessage = String .format ("%s %s" , errorReason , e .getMessage ());
116+ throw ErrorUtils .getProgramFailureException (new ErrorCategory (ErrorCategory .ErrorCategoryEnum .PLUGIN ),
117+ errorReason , errorMessage , ErrorType .USER , true , e );
105118 }
106119 String exactGCSPath = "gs://" + gcsPath .getBucket () + "/" + gcsPath .getName ();
107120 if (exactGCSPath .contains ("*" )) {
0 commit comments