5

Has been working on this for a couple of days and still have no clue what's going on: Got a finch web service, the build.sbt dependencies look like:

  "com.github.finagle" %% "finch-circe" % finchVersion changing(),
  "com.github.finagle" %% "finch-core" % finchVersion changing(),
  "com.github.finagle" %% "finch-jackson" % finchVersion changing(),
  "com.github.finagle" %% "finch-test" % finchVersion changing(),
  "com.twitter" %% "twitter-server" % "1.28.0",

The finch version is 0.14.0. And the endpoint looks like:

  def makeService(statsReceiver: StatsReceiver): Service[Request, Response] = {
    //val getUserCounter = statsReceiver.counter("get_user_counter")
    (
      MyEndpoint.endpoint1()
        :+: SomeEndpoint.deleteEntity()
        :+: SomeEndpoint.createEntity()
        :+: SomeEndpoint.updateEntity()
      ) handle {
      case e: InvalidClientError => Unauthorized(e)
      case e: InvalidContextError => BadRequest(e)
      case e: RelevanceError => BadRequest(e)
      case e: Exception => InternalServerError(e)
    } toService

And I got the error message on the line of "toService" like:

[error] /workplace/relevance-service/src/main/scala/com/company/service/endpoint/serviceEndpoints.scala:39: An Endpoint you're trying to convert into a Finagle service is missing one or more encoders.
[error]
[error]   Make sure Exception is one of the following:
[error]
[error]   * A com.twitter.finagle.http.Response
[error]   * A value of a type with an io.finch.Encode instance (with the corresponding content-type)
[error]   * A coproduct made up of some combination of the above
[error]

And I looked at: https://github.com/finagle/finch/blob/master/docs/src/main/tut/cookbook.md#fixing-the-toservice-compile-error

and tried the lines of:

import io.finch.circe._

And first of all, this io.finch.circe._ is not used in the code since it is grey in the IDE. And I still got the same build error. I'm totally lost here. Anyone can help me out what am I missing here? google/bing around did not get me anything very useful.

Thanks.

Shi Chen
  • 91
  • 2
  • 7
  • 1
    Also I added: import io.circe.generic.auto._ and it does not work. – Shi Chen Apr 17 '17 at 20:27
  • 2
    It's likely that an encoder for one of the types you're serving within the endpoints can't be properly derived by Crice. Try experimenting (e.g., with REPL) if you can derive those encoders manually (i.e., just check if `io.circe.Encoder[YourType]` compiles for each your type). – Vladimir Kostyukov Apr 18 '17 at 17:02
  • The objects is pretty simple that contains fields of types String, Array[String], and Map[String, String], etc. They are pretty straight forward, and I tried to roll back to scala 2.10 and it worked. But moving forward to 2.11, it still fails the build. It is hard to imaging that the encoder cannot handle the situation... – Shi Chen Apr 19 '17 at 17:58

0 Answers0