eed3si9n / gigahorse

Gigahorse is an HTTP client for Scala with multiple backend support.
http://eed3si9n.com/gigahorse
Apache License 2.0
121 stars 25 forks source link

NoClassDefFoundError is thrown when executed with sbt console #34

Open jkugiya opened 6 years ago

jkugiya commented 6 years ago

I tried example code in Quick Start with sbt console, but NoClassDefFoundError was thrown.

OS: Windows 10 sbt: 1.0.4

[error] (OkHttp Dispatcher) java.lang.NoClassDefFoundError: Could not initialize class $line3.$read$$iw$$iw$
[error] java.lang.NoClassDefFoundError: Could not initialize class $line3.$read$$iw$$iw$
[error]         at scala.Function1.$anonfun$andThen$1(Function1.scala:52)
[error]         at gigahorse.support.okhttp.FunctionHandler.onCompleted(FunctionHandler.scala:23)
[error]         at gigahorse.support.okhttp.OkhClient$$anon$1.onResponse(OkhClient.scala:167)
[error]         at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)

However, when executing from the main, there was no problem.

jkugiya commented 6 years ago

Pasting the following code will cause the same problem.

scala> :paste
// Entering paste mode (ctrl-D to finish)
  val http = Gigahorse.http(Gigahorse.config)
  val r = Gigahorse.url("http://api.duckduckgo.com").get.
    addQueryString(
      "q" -> "1 + 1",
      "format" -> "json"
    )
  val f = http.run(r, Gigahorse.asString andThen {_.take(60)})
  Await.result(f, 5.seconds)

However, if you execute it sequentially, the problem will not occur.

scala>   val http = Gigahorse.http(Gigahorse.config)
http: gigahorse.HttpClient = gigahorse.support.okhttp.OkhClient@1cc0b3c8

scala>   val r = Gigahorse.url("http://api.duckduckgo.com").get.
     |     addQueryString(
     |       "q" -> "1 + 1",
     |       "format" -> "json"
     |     )
r: gigahorse.Request = Request(http://api.duckduckgo.com, GET, EmptyBody(), Map(), Map(q -> List(1 + 1), format -> List(json)), None, None, None, None, None, None)

scala>   val f = http.run(r, Gigahorse.asString andThen {_.take(60)})
f: scala.concurrent.Future[String] = Future(<not completed>)

scala>   Await.result(f, 5.seconds)
res21: String = {"Definition":"","AbstractText":"","Answer":{"templates":{"o