Skip to content

Commit

Permalink
Add detail to avro exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Jun 1, 2016
1 parent 60521a8 commit 69841b4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions spark/src/main/scala/geotrellis/spark/io/avro/AvroEncoder.scala
Expand Up @@ -53,7 +53,13 @@ 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 {
format.decode(rec)
} catch {
case e: AvroTypeException =>
throw new AvroTypeException(e.getMessage + ". " +
"If attempting to read multiband tiles, a Reader[K, MultibandTile] is required rather than Reader[K, Tile]. Check to ensure your Reader instance is properly configured.")
}
}

def toJson[T: AvroRecordCodec](thing: T): String = {
Expand All @@ -75,6 +81,12 @@ 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 {
format.decode(rec)
} catch {
case e: AvroTypeException =>
throw new AvroTypeException(e.getMessage + ". " +
"If attempting to read multiband tiles, a Reader[K, MultibandTile] is required rather than Reader[K, Tile]. Check to ensure your Reader instance is properly configured.")
}
}
}

0 comments on commit 69841b4

Please sign in to comment.