Skip to content

Commit 851e341

Browse files
authored
AVRO-3731 [java/gradle-plugin] retry on any schema parse failure (#3384)
With the introduction of the new SchemaParser in 1.12 the variety of errors which can be thrown when an unresolved type is found increased significantly. In the past unresolved type errors were tracked with a brittle regexp. In the newly proposed logic we propose to retry failed parse steps on any AvroRuntimeException. So this works for all past and future avro library versions.
1 parent b41d607 commit 851e341

File tree

1 file changed

+6
-10
lines changed
  • lang/java/gradle-plugin/src/main/java/com/github/davidmc24/gradle/plugin/avro

1 file changed

+6
-10
lines changed

lang/java/gradle-plugin/src/main/java/com/github/davidmc24/gradle/plugin/avro/SchemaResolver.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
import java.util.Set;
77
import java.util.regex.Matcher;
88
import java.util.regex.Pattern;
9+
import org.apache.avro.AvroRuntimeException;
910
import org.apache.avro.Schema;
10-
import org.apache.avro.SchemaParseException;
1111
import org.gradle.api.GradleException;
1212
import org.gradle.api.file.ProjectLayout;
1313
import org.gradle.api.logging.Logger;
1414

1515
class SchemaResolver {
16-
private static Pattern ERROR_UNKNOWN_TYPE = Pattern.compile("(?i).*(undefined name|not a defined name|type not supported).*");
1716
private static Pattern ERROR_DUPLICATE_TYPE = Pattern.compile("Can't redefine: (.*)");
1817

1918
private final ProjectLayout projectLayout;
@@ -58,15 +57,10 @@ private void processSchemaFile(ProcessingState processingState, FileState fileSt
5857
} else {
5958
logger.info("Processed {}", path);
6059
}
61-
} catch (SchemaParseException ex) {
60+
} catch (AvroRuntimeException ex) {
6261
String errorMessage = ex.getMessage();
63-
Matcher unknownTypeMatcher = ERROR_UNKNOWN_TYPE.matcher(errorMessage);
6462
Matcher duplicateTypeMatcher = ERROR_DUPLICATE_TYPE.matcher(errorMessage);
65-
if (unknownTypeMatcher.matches()) {
66-
fileState.setError(ex);
67-
processingState.queueForDelayedProcessing(fileState);
68-
logger.debug("Found undefined name in {} ({}); will try again", path, errorMessage);
69-
} else if (duplicateTypeMatcher.matches()) {
63+
if (duplicateTypeMatcher.matches()) {
7064
String typeName = duplicateTypeMatcher.group(1);
7165
if (fileState.containsDuplicateTypeName(typeName)) {
7266
throw new GradleException(
@@ -79,7 +73,9 @@ private void processSchemaFile(ProcessingState processingState, FileState fileSt
7973
logger.debug("Identified duplicate type {} in {}; will re-process excluding it", typeName, path);
8074
}
8175
} else {
82-
throw new GradleException(String.format("Failed to resolve schema definition file %s", path), ex);
76+
fileState.setError(ex);
77+
processingState.queueForDelayedProcessing(fileState);
78+
logger.debug("Found error in {} ({}); will try again", path, errorMessage);
8379
}
8480
} catch (IOException ex) {
8581
throw new GradleException(String.format("Failed to resolve schema definition file %s", path), ex);

0 commit comments

Comments
 (0)