You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "clesaec (via GitHub)" <gi...@apache.org> on 2023/08/07 07:25:28 UTC

[GitHub] [avro] clesaec commented on a diff in pull request #2420: AVRO-3791: [Java] Include field in readField AvroTypeException

clesaec commented on code in PR #2420:
URL: https://github.com/apache/avro/pull/2420#discussion_r1285478016


##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java:
##########
@@ -257,7 +258,12 @@ protected Object readRecord(Object old, Schema expected, ResolvingDecoder in) th
    */
   protected void readField(Object record, Field field, Object oldDatum, ResolvingDecoder in, Object state)
       throws IOException {
-    data.setField(record, field.name(), field.pos(), read(oldDatum, field.schema(), in), state);
+    try {
+      data.setField(record, field.name(), field.pos(), read(oldDatum, field.schema(), in), state);
+    } catch(AvroTypeException exception) {
+      String message = "Field \"" + field.name() + "\" content mismatch: " + exception.getMessage();
+      throw new AvroTypeException(message);

Review Comment:
   In order to not loose the stack trace; use constructor with "cause" parameter; either
   `throw new AvroTypeException(message, exception);`
   or, to avoid having 2 AvroTypeException
   `throw new AvroTypeException(message, exception.getCause());`
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org