Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 23 20:45
    joroKr21 closed #1478
  • Sep 23 20:45

    joroKr21 on master

    Testing EndpointResults without… F.raiseError instead of throw Get rid of dispatcher in more p… and 5 more (compare)

  • Sep 23 20:45
    joroKr21 closed #1525
  • Sep 23 20:36
    joroKr21 edited #1525
  • Sep 23 20:35
    joroKr21 labeled #1525
  • Sep 23 20:35
    joroKr21 assigned #1525
  • Sep 23 20:35
    joroKr21 ready_for_review #1525
  • Sep 23 20:34
    joroKr21 edited #1525
  • Sep 23 20:34
    joroKr21 edited #1525
  • Sep 23 20:34
    joroKr21 edited #1525
  • Sep 23 20:32
    joroKr21 synchronize #1525
  • Sep 23 20:18
    joroKr21 synchronize #1525
  • Sep 23 19:40
    joroKr21 synchronize #1525
  • Sep 23 19:38
    joroKr21 synchronize #1525
  • Sep 23 19:22
    joroKr21 opened #1525
  • Sep 23 17:38

    joroKr21 on master

    Relax constraints from Async to… Merge pull request #1523 from j… (compare)

  • Sep 23 17:38
    joroKr21 closed #1523
  • Sep 23 17:37

    joroKr21 on master

    Fix doc links for Scala 2.12 - … Merge pull request #1524 from j… (compare)

  • Sep 23 17:37
    joroKr21 closed #1524
  • Sep 23 17:25
    joroKr21 labeled #1524
ComFreek
@ComFreek
But ideally, we would just return from the lambda passed to get(...)
ComFreek
@ComFreek
Other question: given a list of endpoints, can I automatically pretty-print it somehow? Such that the user gets a list of GET /post/list, POST /post/edit
Ryan Plessner
@rpless
for the first I example I tend to use fold. opt.fold[Output[String]](BadRequest(???))(_ => Ok("test")) note you do have provide the type parameter to the fold
as for the pretty-printing there as a toString that kinda does this, but you would have fiddle with the output to get the format you want
ComFreek
@ComFreek
@rpless Thanks. For the prettyprinting of endpoints, in my case I get
"(GET /help :+: (POST /archive :: build-light :+: (POST /archive :: build :+: (POST /fact :: add :: body :+: (GET /fact :: list :+: (GET /scroll :: list :+: (POST /scroll :: apply :: body :+: GET /debug :: situationtheory :: print)))))))"
which is not very helpful
even the parentheses look strangely unbalanced
e.g. GET /help is a single endpoint
ComFreek
@ComFreek
--> now posted on Finagle mailing list: https://groups.google.com/g/finaglers/c/LM5KzvSRpcI
Ryan Plessner
@rpless
the parens on that print out seem correct. basically every :+: introduces a set of parens so the endpoints wind up being fairly nested
re: your question in Finaglers auto generating developer docs isn't something that is supported at the moment. its a hard problem that we haven't solved. its one of the oldest issues on the repo finagle/finch#73
zanpakuto
@zanpakuto

I'm using finchx 0.32.1. I wrote below code, but unable to understand the reason for compilation error : "Cannot resolve overloaded method"

Can anyone please help me understand? Appreciate the help.

private val greetByName : Endpoint[IO, Json] = get(path("hello") :: paramOption("name")) = {
  Ok("Hello".asJson)
}
Ryan Plessner
@rpless
Hi @zanpakuto. I think the issue is that you are using paramOption which means the mapper is going to want an argument to the function you are using for mapping. something like this might be what you are looking for:
  private val greetByName: Endpoint[IO, Json] = get(path("hello") :: paramOption("name"))({ name: Option[String] =>
    Ok("Hello".asJson)
  })
zanpakuto
@zanpakuto
@rpless , thank you. The build is fine now.
Andrew Roberts
@aroberts
I have a POST endpoint consuming jsonBody and decoding via Circe, and I don’t seem to be able to catch the decoding error if it occurs- I want to be able to return a 400 response when bad json is submitted, but the circe DecodingFailure is wrapped in a finch-private CirceError case class. Is there a better approach to achieve this end?
Ryan Plessner
@rpless
@aroberts you should be able to access the Circe error even if its wrapped in Finch's private class. getCause should give you access to the underlying Circe error
Andrew Roberts
@aroberts
oh, interesting. I’m used to declarations shaped like class CirceError(cause: Error) extends Exception(cause) with NoStackTrace. My assumption was that CirceError.cause shadowed Exception.cause, but didn’t actually override it
Daave
@Daave_gitlab
Is there a way to get all params from a application/x-www-form-urlencoded in a Map
In play I can do it like so
def formHandler: Action[Map[String, Seq[String]]] = Action.async(parse.formUrlEncoded)
I can use param but I need to get all the params and they can be dynamic
Is there a way to do this?
Sergey Kolbasov
@sergeykolbasov
hmm, I think you need your own endpoint that is going to extract it for you. You could use something like root.map(request => request.getParams()) to get the Endpoint[F, List[Entry[String, String]]
Duncan Hills Coffee Company
@DuncanHills
can someone publish 0.32.1 to maven central?
0.31 is the latest version there...
kinda strange since that release was in march
ComFreek
@ComFreek
I copied the exception encoder from the user guide: https://finagle.github.io/finch/user-guide.html#errors
But it apparently doesn't take effect, I still get 500 internal server errors with empty body upon exceptions
Where do I have to define it?
ComFreek
@ComFreek
image.png
e.g. in this code (please ignore IntelliJ's broken graying), on runtime I get an exception and the println line is not even reached
ComFreek
@ComFreek
Not even this works:
import io.finch._
import cats.effect.IO
import com.twitter.finagle.Http
import com.twitter.io.Buf
import com.twitter.util.Await

object Test extends App with Endpoint.Module[IO] {
  implicit val encodeException: Encode.Text[Exception] =
    Encode.text((_, cs) => Buf.ByteArray.Owned("ERR!".getBytes(cs.name)))

  val api: Endpoint[IO, String] = get("hello") {
    throw new Exception("test")
    Ok("Hello, World!")
  }
  Await.ready(Http.server.serve(":8080", api.toServiceAs[Text.Plain]))
}
http://127.0.0.1:8080/hello does not output ERR! in the browser
Sergey Kolbasov
@sergeykolbasov

Hello @ComFreek

It's a bit trickier. That default encoder covers only "exceptions" inside of Output, i.e. BadRequest(new Exception("test"))

If you would like to cover all the exceptions, you need to set up filter on top of finagle's Service[Request, Response] or use middleware filters like here:
https://github.com/finagle/finch/blob/master/examples/src/main/scala/io/finch/middleware/Main.scala
shortly speaking in Finch we prefer to avoid exceptions as a mechanism and rather deal with errors as values, as it's much cleaner and easier to reason about
import io.finch._
import cats.effect.IO
import com.twitter.finagle.Http
import com.twitter.io.Buf
import com.twitter.util.Await

object Test extends App with Endpoint.Module[IO] {
  implicit val encodeException: Encode.Text[Exception] =
    Encode.text((_, cs) => Buf.ByteArray.Owned("ERR!".getBytes(cs.name)))

  val api: Endpoint[IO, String] = get("hello") {
    if (Random.nextBoolean()) {
      Ok("Hello, World!")
    } else {
      BadRequest(new Exception("oh no"))
    }
  }
  Await.ready(Http.server.serve(":8080", api.toServiceAs[Text.Plain]))
}
This should work
ComFreek
@ComFreek
@sergeykolbasov I understand your philosophy on values over exceptions, but for debugging receiving just a 500 Internal Server Error is utterly lacking.
I need those stack traces
Let me see if I can get the filter approach working
Sergey Kolbasov
@sergeykolbasov

It's a method of IO.

Although, it works for any F[_] : Apply with import cats.syntax.all._

ComFreek
@ComFreek
Does that look idiomatic?
If so, any chance we can integrate this in the Finch docs somehow?
(not necessarily the full code, a simplified version might suffice)
Sergey Kolbasov
@sergeykolbasov
I have a plan to make a major update on the documentation, but probably after Black Friday, as now we're quite busy
ComFreek
@ComFreek
Okay, great. HTTP 500 errors without response body costed me more debugging hours than I am willing to admit.