aleph

pithyless 2019-11-20T18:46:14.049800Z

I'm seeing this kind of error after pathom Index Explorer is trying to serialize the entire context and push it across the wire.

java.lang.Exception: Not supported: class com.wsscode.pathom.connect$fn__54398
java.lang.RuntimeException: java.lang.Exception: Not supported: class com.wsscode.pathom.connect$fn__54398
clojure.lang.ExceptionInfo: Malformed application/transit+json in :muuntaja/encode
    format: "application/transit+json"
      type: :muuntaja/encode

pithyless 2019-11-20T18:46:55.049900Z

What is the best way to configure muuntaja to simply ignore things it can't encode correctly in application/transit+json?

pithyless 2019-11-20T18:47:21.050100Z

Is there a way to configure a default handler?

ikitommi 2019-11-20T18:53:46.050300Z

You are returning a function, which can't be serialized. I don't think disabling encoding helps here. I would double-check how to serialize the context.

pithyless 2019-11-20T18:53:50.050500Z

Just trying to think this through, I've tried e.g.:

(def generic-function-writer
  (transit/write-handler
   (constantly "fn")
   (fn [v] (pr-str v))
   (fn [v] (pr-str v))))


(def muuntaja-instance
  (muuntaja/create
   (-> muuntaja/default-options
       (assoc-in
        [:formats "application/transit+json" :encode-opts]
        {:handlers {java.util.function.Function generic-function-writer}}))))

pithyless 2019-11-20T18:54:10.050700Z

But it doesn't seem to be called (would it match the java.util.function.Function?

ikitommi 2019-11-20T18:55:00.050900Z

you can set response "Content-Type" manually to disable the automatic encoding.

ikitommi 2019-11-20T18:55:41.051100Z

... but, will most likely to blow up in the web server. Maybe you should invoke the function yourself?

pithyless 2019-11-20T18:57:20.051300Z

To clarify, I'm using reitit-http and my router has {:data {:muuntaja my-muuntaja-instance}}.

pithyless 2019-11-20T18:57:49.051500Z

I expect, that the (interceptor.muuntaja/format-response-interceptor) should pick up this custom muuntaja instance?

pithyless 2019-11-20T18:59:20.051700Z

This is a weird setup - I didn't expect to get hit with a serialization problem like this. But it looks like a real thing, and the expected workaround for now: https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/connect/exploration.html#_fixing_transit_encoding_issues

pithyless 2019-11-20T19:26:02.051900Z

I've done as you suggested for now @ikitommi - just invoking the custom transit writer myself for this specific route. I'd still like to circle back to this later and figure out a nicer solution. Thanks!

wcalderipe 2019-11-20T22:54:10.052100Z

Thanks for sharing @pithyless I'll definitely listen to it today