File tree 1 file changed +12
-1
lines changed
src/main/java/io/cdap/plugin/gcp/gcs/source
1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 17
17
package io .cdap .plugin .gcp .gcs .source ;
18
18
19
19
import com .google .auth .Credentials ;
20
+ import com .google .cloud .storage .Bucket ;
20
21
import com .google .cloud .storage .Storage ;
21
22
import com .google .cloud .storage .StorageException ;
22
23
import com .google .common .base .Strings ;
55
56
import java .util .HashMap ;
56
57
import java .util .List ;
57
58
import java .util .Map ;
59
+ import java .util .Objects ;
58
60
import java .util .regex .Pattern ;
59
61
import javax .annotation .Nullable ;
60
62
@@ -122,7 +124,16 @@ public void prepareRun(BatchSourceContext context) throws Exception {
122
124
String location = null ;
123
125
try {
124
126
// 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 ();
126
137
} catch (StorageException e ) {
127
138
String errorReason = String .format ("Error code: %s, Unable to access GCS bucket '%s'. " ,
128
139
e .getCode (), bucketName );
You can’t perform that action at this time.
0 commit comments