Fork me on GitHub
#aleph
<
2019-11-20
>
pithyless18:11:14

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

pithyless18:11:55

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

pithyless18:11:21

Is there a way to configure a default handler?

ikitommi18:11:46

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.

pithyless18:11:50

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}}))))

pithyless18:11:10

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

ikitommi18:11:00

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

ikitommi18:11:41

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

pithyless18:11:20

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

pithyless18:11:49

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

pithyless18:11:20

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

pithyless19:11:02

I've done as you suggested for now @U055NJ5CC - 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!