Skip to content

Commit

Permalink
Merge pull request #1505 from moradology/fix/avro-type-error-detail
Browse files Browse the repository at this point in the history
Add detail to avro exception message
  • Loading branch information
lossyrob authored Jun 28, 2016
2 parents 6700643 + e75c336 commit 4a80fb9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions spark/src/main/scala/geotrellis/spark/io/avro/AvroEncoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ object AvroEncoder {

val reader = new GenericDatumReader[GenericRecord](writerSchema, schema)
val decoder = DecoderFactory.get().binaryDecoder(decompress(bytes), null)
val rec = reader.read(null.asInstanceOf[GenericRecord], decoder)
format.decode(rec)
try {
val rec = reader.read(null.asInstanceOf[GenericRecord], decoder)
format.decode(rec)
} catch {
case e: AvroTypeException =>
throw new AvroTypeException(e.getMessage + ". " +
"This can be caused by using a type parameter which doesn't match the object being deserialized.")
}
}

def toJson[T: AvroRecordCodec](thing: T): String = {
Expand All @@ -74,7 +80,13 @@ object AvroEncoder {

val reader = new GenericDatumReader[GenericRecord](schema)
val decoder = DecoderFactory.get().jsonDecoder(schema, json)
val rec = reader.read(null.asInstanceOf[GenericRecord], decoder)
format.decode(rec)
try {
val rec = reader.read(null.asInstanceOf[GenericRecord], decoder)
format.decode(rec)
} catch {
case e: AvroTypeException =>
throw new AvroTypeException(e.getMessage + ". " +
"This can be caused by using a type parameter which doesn't match the object being deserialized.")
}
}
}

0 comments on commit 4a80fb9

Please sign in to comment.