File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
src/main/java/io/cdap/plugin/gcp/gcs/source Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1717package io .cdap .plugin .gcp .gcs .source ;
1818
1919import com .google .auth .Credentials ;
20+ import com .google .cloud .storage .Bucket ;
2021import com .google .cloud .storage .Storage ;
2122import com .google .cloud .storage .StorageException ;
2223import com .google .common .base .Strings ;
5556import java .util .HashMap ;
5657import java .util .List ;
5758import java .util .Map ;
59+ import java .util .Objects ;
5860import java .util .regex .Pattern ;
5961import javax .annotation .Nullable ;
6062
@@ -122,7 +124,16 @@ public void prepareRun(BatchSourceContext context) throws Exception {
122124 String location = null ;
123125 try {
124126 // Get location of the source for lineage
125- location = storage .get (bucketName ).getLocation ();
127+ Bucket bucket = storage .get (bucketName );
128+ if (Objects .isNull (bucket )) {
129+ String errorReason = String .format ("Unable to access GCS bucket '%s'." ,
130+ bucketName );
131+ collector .addFailure (
132+ String .format ("%s Ensure you entered the correct bucket path." , errorReason ),
133+ null );
134+ collector .getOrThrowException ();
135+ }
136+ location = bucket .getLocation ();
126137 } catch (StorageException e ) {
127138 String errorReason = String .format ("Error code: %s, Unable to access GCS bucket '%s'. " ,
128139 e .getCode (), bucketName );
You can’t perform that action at this time.
0 commit comments