Collected route tries are non-exhaustive, leading to `java.util.NoSuchElementException` on missing route method
megri opened this issue · 1 comments
Since #27 I believe, Main.DefaultHandler
throws a NoSuchElementException for any incoming request which uses a method that's not used in any route (this also oddly enough results in a 200 response).
The is the line that triggers the error: https://github.com/lihaoyi/cask/blob/4617b7e1f70eaa902b1aa492413a3a8ddc1491dd/cask/src/cask/main/Main.scala#L89
I think this could be resolved by adding a .withDefaultValue(DispatchTrie.empty)
to the map in Main.prepareRouteTries
, provided a static empty instance of DispatchTrie is possible to create. Another solution is to change L89 to a routeTries.get(effectiveMethod)
, but I believe that would add more overhead to each call and also make it easier for users to fall into the trap of missing this peculiarity if overriding the defaultHandler method on Main.
edit: A use-site workaround for now is to override the default routeTries
with
override def routeTries: Map[String,DispatchTrie[(Routes, EndpointMetadata[_])]] =
super.routeTries.withDefaultValue(DispatchTrie.construct(-1, Seq.empty))
I can't recreate this error with the 0.7.11 version on Scala 3 so I'm closing.