Skip to content

Commit 204080b

Browse files
Merge pull request #1481 from data-integrations/improve-error-message
[PLUGINk-1807] Add resource name in validation error message
2 parents c5f4d69 + 16a22b1 commit 204080b

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/main/java/io/cdap/plugin/gcp/bigquery/util/BigQueryUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ public static Table getBigQueryTable(String projectId, String dataset, String ta
672672
*/
673673
public static void validateBucket(String bucket, String bucketPropertyName, FailureCollector collector) {
674674
// Allowed character validation for bucket name as per https://cloud.google.com/storage/docs/naming
675-
String errorMessage = "Bucket name can only contain lowercase letters, numbers, '.', '_', and '-'.";
675+
String errorMessage = "Bucket name '%s' can only contain lowercase letters, numbers, '.', '_', and '-'.";
676676
match(bucket, bucketPropertyName, BUCKET_PATTERN, collector, errorMessage);
677677
}
678678

@@ -685,7 +685,7 @@ public static void validateBucket(String bucket, String bucketPropertyName, Fail
685685
*/
686686
public static void validateDataset(String dataset, String datasetPropertyName, FailureCollector collector) {
687687
// Allowed character validation for dataset name as per https://cloud.google.com/bigquery/docs/datasets
688-
String errorMessage = "Dataset name can only contain letters (lower or uppercase), numbers and '_'.";
688+
String errorMessage = "Dataset name '%s' can only contain letters (lower or uppercase), numbers and '_'.";
689689
match(dataset, datasetPropertyName, DATASET_PATTERN, collector, errorMessage);
690690
}
691691

@@ -698,7 +698,7 @@ public static void validateDataset(String dataset, String datasetPropertyName, F
698698
*/
699699
public static void validateTable(String table, String tablePropertyName, FailureCollector collector) {
700700
// Allowed character validation for table name as per https://cloud.google.com/bigquery/docs/tables
701-
String errorMessage = "Table name can only contain letters (lower or uppercase), numbers, '_' and '-'.";
701+
String errorMessage = "Table name '%s' can only contain letters (lower or uppercase), numbers, '_' and '-'.";
702702
match(table, tablePropertyName, TABLE_PATTERN, collector, errorMessage);
703703
}
704704

@@ -739,7 +739,7 @@ private static void match(String text, String propertyName, String pattern,
739739
if (!Strings.isNullOrEmpty(text)) {
740740
Pattern p = Pattern.compile(pattern);
741741
if (!p.matcher(text).matches()) {
742-
collector.addFailure(errorMessage, null).withConfigProperty(propertyName);
742+
collector.addFailure(String.format(errorMessage, text), null).withConfigProperty(propertyName);
743743
}
744744
}
745745
}

src/main/java/io/cdap/plugin/gcp/common/GCPErrorDetailsProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ private ProgramFailureException getProgramFailureException(HttpResponseException
101101
}
102102

103103
private String getErrorMessage(GoogleJsonResponseException exception) {
104+
if (!Strings.isNullOrEmpty(exception.getMessage())) {
105+
return exception.getMessage();
106+
}
104107
if (exception.getDetails() != null) {
105108
try {
106109
return exception.getDetails().toPrettyString();

src/test/java/io/cdap/plugin/gcp/bigquery/sink/BigQuerySinkConfigTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class BigQuerySinkConfigTest {
4242
Method validateTimePartitioningColumnMethod;
4343
Map<String, String> arguments;
4444
private static final String invalidTableNameErrorMessage =
45-
"Table name can only contain letters (lower or uppercase), numbers, '_' and '-'.";
45+
"Table name '%s' can only contain letters (lower or uppercase), numbers, '_' and '-'.";
4646

4747
@Before
4848
public void setup() throws NoSuchMethodException {
@@ -297,7 +297,8 @@ public void testValidateTableNameWithInvalidTableName() {
297297
config = configBuilder.setTable(tableName).build();
298298
config.validate(collector);
299299
Assert.assertEquals(1, collector.getValidationFailures().size());
300-
Assert.assertEquals(invalidTableNameErrorMessage, collector.getValidationFailures().get(0).getMessage());
300+
Assert.assertEquals(String.format(invalidTableNameErrorMessage, tableName),
301+
collector.getValidationFailures().get(0).getMessage());
301302
}
302303
}
303304

0 commit comments

Comments
 (0)