forked from allegro/json-avro-converter
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add caching in ci * Log offending values * Update readme
- Loading branch information
Showing
4 changed files
with
54 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 10 additions & 8 deletions
18
converter/src/main/java/tech/allegro/schema/json2avro/converter/AvroTypeExceptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
package tech.allegro.schema.json2avro.converter; | ||
|
||
import static java.util.stream.Collectors.*; | ||
|
||
import java.util.Deque; | ||
|
||
import org.apache.avro.AvroTypeException; | ||
|
||
class AvroTypeExceptions { | ||
static AvroTypeException enumException(Deque<String> fieldPath, String expectedSymbols) { | ||
static AvroTypeException enumException(Deque<String> fieldPath, String expectedSymbols, Object offendingValue) { | ||
return new AvroTypeException(new StringBuilder() | ||
.append("Field ") | ||
.append(PathsPrinter.print(fieldPath)) | ||
.append(" is expected to be of enum type and be one of ") | ||
.append(expectedSymbols) | ||
.append(", but it is: ") | ||
.append(offendingValue) | ||
.toString()); | ||
} | ||
|
||
static AvroTypeException unionException(String fieldName, String expectedTypes, Deque<String> offendingPath) { | ||
static AvroTypeException unionException(String fieldName, String expectedTypes, Deque<String> offendingPath, Object offendingValue) { | ||
return new AvroTypeException(new StringBuilder() | ||
.append("Could not evaluate union, field ") | ||
.append(fieldName) | ||
.append(" is expected to be one of these: ") | ||
.append(expectedTypes) | ||
.append(". If this is a complex type, check if offending field: ") | ||
.append(". If this is a complex type, check if offending field (path: ") | ||
.append(PathsPrinter.print(offendingPath)) | ||
.append(" adheres to schema.") | ||
.append(") adheres to schema: ") | ||
.append(offendingValue) | ||
.toString()); | ||
} | ||
|
||
static AvroTypeException typeException(Deque<String> fieldPath, String expectedType) { | ||
static AvroTypeException typeException(Deque<String> fieldPath, String expectedType, Object offendingValue) { | ||
return new AvroTypeException(new StringBuilder() | ||
.append("Field ") | ||
.append(PathsPrinter.print(fieldPath)) | ||
.append(" is expected to be type: ") | ||
.append(expectedType) | ||
.append(", but it is: ") | ||
.append(offendingValue) | ||
.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters