Fork me on GitHub
#pedestal
<
2017-03-21
>
souenzzo04:03:21

I'm thinking of making an interceptor to open datomic connection (single db/connecton for all others interceptos/handler/fns. It's a good idea? Does anyone do some like?

manutter5110:03:34

Well this is weird. I started a new pedestal service project (weekend project) and added in the ring-middlewares session interceptor with a custom redis-based session store. Saturday it all worked fine, and then on Sunday I started getting No matching ctor found for class io.pedestal.http.ring_middlewares$response_fn_adapter$fn__11673 every time I try to start a REPL

manutter5110:03:02

I’ve commented out the work I did since the last known good state, and I’ve added in the exclusions recommended by lein deps :tree and done numerous lein cleans. Not sure how to proceed from here.

manutter5110:03:36

I have to head in to work now, but I’ll check this channel later in case anybody has any ideas/suggestions

manutter5110:03:28

Here’s a relevant chunk of code from my service.clj file

deg12:03:37

<vent> This has to be the single most frustrating part of Clojure programming. I thought spec would clean up all these mess, but not yet, I guess </vent> I just wrote a few dozen lines of in the ..._service.end file, trying out what I can do with Vase. Then restarted the program and got barfed at with "Don't know how to create ISeq from: clojure.lang.Keyword" from deep in the EdnReader parsing the file. Couldn't the error message have the grace to at least report a line number, if not the full line of input or at least the unexpected keyword?? I'll find the problem, of course. I'll divide-and-conquer until it's down to an obvious small bit. Then, I'll slap my head and fix my dumb typo. But, why!!

deg12:03:12

Yeah, found it. And, yeah, it was a silly typo. And, yeah, I fixed it and restarted again. And, yup, there was another typo. And... a bunch later all fixed and the program starts. But, argghhhh!!

rauh12:03:20

@deg Printing the entire stacktrace didn't show the line? With Cursive you can even "print last exception" and just click on it and you usually see the problem right away.

deg12:03:54

No. It showed the line that called the EdnReader. The root problem, I guess, is that Vase is reading a data file, not compiling a program. But, the data file has the size, complexity, and written-by-a-fallible-human attributes of a program.

ddeaguiar13:03:57

@souenzzo, using an interceptor to create a Datomic connection and make it available to downstream interceptors/handlers is perfectly acceptable

ddeaguiar13:03:43

@souenzzo, it’s common to make both a db and connection available

ddeaguiar18:03:14

Thanks for pointing that out. I have seen it before but never used it on a project. You may also be interested in http://www.rkn.io/2014/12/16/datomic-antipatterns-eager-conn/

ddeaguiar18:03:46

I’m pretty sure that project influenced my approach as well

ddeaguiar13:03:25

@manutter51, I can’t identify the root cause of your error from the snippet you pasted but I’m curious as to why you don’t enable sessions via the service map.

mtnygard13:03:27

@manutter51 That is a very strange exception. Have you changed Pedestal or Clojure versions in your project.clj file?

ddeaguiar13:03:59

my question is likely a tangent though...

mtnygard13:03:40

@manutter51 lein clean doesn't remove quite everything... you may need to prune some parts of your ~/.m2/repository tree. Try removing org/clojure and io/pedestal to force a re-download of those jars.

mtnygard13:03:11

@deg When I first read your complaint about the error I thought it was something internal to Clojure itself. On second glance, though, it looks like something we might be able to address in Vase. Can you send me some details in a PM? I'd like to see if we can make a better error message.

deg13:03:25

Ok. I'll PM you more details in a minute

deg15:03:21

For debugging my Vase app, what is the syntax for a query that returns the entire db?

mtnygard15:03:20

@deg There are two ways to approach this. One is to use the datoms function and just get all datoms in total. The other would be to run a query with [:find ?e ?a ?v :where [?e ?a ?v]]. The second one only works if your whole db fits in memory.

deg15:03:16

Thanks. Memory is not a problem at this stage; I'd still fit on a PDP-8 🙂

deg15:03:10

But, for your datoms solution... where can I get hold of the db? It seems to be passed implicitly in the current query syntax.

deg15:03:24

Hmm, and for the second solution, I get` Interceptor Exception: :db.error/insufficient-binding Insufficient binding of db clause: [?e ?a ?v] would cause full scan`

mtnygard15:03:14

You'd do that with an interceptor: #vase/intercept {:name :dump-db :enter (fn [ctx] (assoc ctx :response {:status 200 :body (datomic.api/datoms (-> ctx :request :db) :eavt)}))}

mtnygard15:03:32

Ah, that's new.

mtnygard15:03:46

Stick with datoms then, I guess.

deg15:03:15

1) So, I assume that's some zealous protection against loading the whole db? Why needed? 2) In you snippet, what is namespace d?

mtnygard15:03:08

Edited. I wrote that off the top of my head, then remembered that it would be evaluated in a context that may not have the usual requires.

mtnygard15:03:29

As for your first question, I can't answer it. That would be a Q for the Datomic gang.

deg15:03:42

So, with "/dump" <#C49BSM9B3|vase>/intercept {:name :dump-db :enter (fn [ctx] (assoc ctx :response {:status 200 :body (datomic.api/datoms (-> ctx :request :db) :eavt)}))} I get `Interceptor Exception: You're trying to use something as an interceptor that isn't supported by the protocol; Perhaps you need to extend it?`

mtnygard15:03:20

"/dump" {:get <#C49BSM9B3|vase>/intercept {:name :dump-db :enter (fn [ctx] (assoc ctx :response {:status 200 :body (datomic.api/datoms (-> ctx :request :db) :eavt)}))}}

mtnygard15:03:41

It's like any other literal... has to have a verb

deg15:03:16

Hmm, now the query is not returning. But, I have to run help my kids. Back in a bit, hopefully after I find my typo.

deg16:03:53

That body (datomic.api/datoms (-> ctx :request :db) :eavt) returns an object that does not implement :default-content-type. It is datomic.db$datoms$reify__1965@26eb24d0

manutter5116:03:14

@ddeaguiar @mtnygard Thanks for the responses. I’m fairly new to pedestal service, and I missed the part about configuring enable-session in the service map, so I’ll try that when I get home. I did happen to try upgrading to alpha15 and reverted back to alpha14 (of 1.9.0) when I got a bunch of spec errors. I tried deleting the pedestal stuff from my .m2 directory but didn’t think of doing the same with org.clojure, so I’ll try that also.

manutter5116:03:20

s/agai/again

mtnygard16:03:03

@deg try wrapping it with seq

deg16:03:50

Tried that. Didn't work. clojure.lang.LazySeq@1c94d503

deg16:03:54

and first of that gives...

deg16:03:51

datomic.db.Datum@3aad15de

ddeaguiar16:03:28

@manutter51, check out http://pedestal.io/reference/service-map re: enabling session via the service map.

manutter5118:03:26

Yeah, I found it right away once I knew I ought to be looking for it 🙂