Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a better worded exception of unsupported SpecificRecord coder case #4815

Merged
merged 3 commits into from
May 25, 2023

Conversation

shnapz
Copy link
Contributor

@shnapz shnapz commented May 19, 2023

No description provided.

@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #4815 (c862333) into main (8b1caa6) will increase coverage by 0.03%.
The diff coverage is 100.00%.

❗ Current head c862333 differs from pull request most recent head 3dd43ae. Consider uploading reports for the commit 3dd43ae to get more accurate results

@@            Coverage Diff             @@
##             main    #4815      +/-   ##
==========================================
+ Coverage   62.40%   62.43%   +0.03%     
==========================================
  Files         280      280              
  Lines       10407    10410       +3     
  Branches      760      781      +21     
==========================================
+ Hits         6495     6500       +5     
+ Misses       3912     3910       -2     
Impacted Files Coverage Δ
...fy/scio/coders/instances/kryo/AvroSerializer.scala 100.00% <ø> (ø)
.../main/scala/com/spotify/scio/pubsub/PubsubIO.scala 9.87% <ø> (ø)
...cala/com/spotify/scio/coders/KryoAtomicCoder.scala 70.31% <100.00%> (+0.23%) ⬆️
...com/spotify/scio/coders/instances/AvroCoders.scala 84.61% <100.00%> (+1.75%) ⬆️
...spotify/scio/coders/instances/BeamTypeCoders.scala 77.77% <100.00%> (+2.77%) ⬆️
...ify/scio/io/dynamic/syntax/SCollectionSyntax.scala 90.38% <100.00%> (+0.58%) ⬆️
...in/scala/com/spotify/scio/values/SCollection.scala 94.75% <100.00%> (+0.72%) ⬆️
.../com/spotify/scio/parquet/avro/ParquetAvroIO.scala 87.71% <100.00%> (ø)
...arquet/avro/dynamic/syntax/SCollectionSyntax.scala 92.30% <100.00%> (ø)
...c/main/scala/com/spotify/scio/testing/Pretty.scala 91.89% <100.00%> (-0.97%) ⬇️

s"Avro schema by instantiating $clazz. Use only a concrete type implementing " +
s"SpecificRecord or use GenericRecord type in your transformations if a concrete " +
s"type is not known in compile time."
throw new Throwable(msg, cause)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't worth chaining the exception here, as the one raised by

SpecificData.get().getSchema(clazz)

is already suppressed. We're already in a fallback/recover case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • my intuition is that this extra info won't hurt
  • this would make clear if failure happens for anything other than "constructor not found", like getSchema might fail because of some bug in apache avro

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'd also change the exception type with a IllegalArgumentException and if using the try/cath, prefer

case NonFatal(e) =>

instead of catching any Throwable

Comment on lines 148 to 149
// Otherwise create a default instance and call getSchema
.getOrElse(getSchemaFromEmptyInstance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orElse will make this more idiomatic IMHO

Suggested change
// Otherwise create a default instance and call getSchema
.getOrElse(getSchemaFromEmptyInstance)
.orElse(Try(clazz.getDeclaredConstructor().newInstance().getSchema))
.getOrElse {
val msg = ...
throw new RuntimeException(msg)
}

@shnapz shnapz marked this pull request as ready for review May 23, 2023 20:41
@shnapz shnapz requested a review from RustedBones May 24, 2023 14:59
@shnapz shnapz merged commit 148e34c into main May 25, 2023
@shnapz shnapz deleted the akabas/avrocoder-better-exception branch May 25, 2023 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants