Fork me on GitHub
#mount
<
2017-03-16
>
lucian30305:03:54

i started a new luminus template project and added one sql function and set up my db urls so that everything's working with the db connection itself but i'm getting a CompilerException java.lang.IllegalArgumentException: db-spec mount.core.DerefableState@5759e7ca is missing a required parameter, compiling:(checker.clj:26:34) when i try to compile or run a repl when i try to access that db function from a second namespace. if i run mount.core/start in that second namespace, it works for the repl and with lein run but lein uberjar fails and it seems like that is unnecessary as mount.core/start is called from the function that starts the app. if i remove the call to the db function in that second namespace, it works fine. i also tried requiring this second namespace in the core namespace that starts the app but that didn't seem to have any effect. any ideas?

tolitius15:03:06

@lucian303 can you share some code? you only need a single (mount/start) for everything to work. In case of an uberjar, usually, a (mount/start) is called from within a -main method in "xyz" namespace. In order for it to work, that "xyz" namespace should (:require [...]) namespaces with states. It does not need to require all of them, as it would find them transitively: i.e. if you require just a namespace a that in turn requires a namespace b, a is all you need.

lucian30319:03:35

@tolitius i set up a repo here to demonstrate the problem: https://github.com/lucian303/luminus-test ... the only changes i made from lein new luminus testing +swagger +service +mysql are to add the db urls to profiles.clj, my own db function to the sql file and a call to that function in the testing.routes.services namespace to show the problem. i can only start the repl / server if the call to mount in testing.routes.services is there, but that doesn't help the uberjar which throws an exception cause the db is not started. also, as u say, that should be unnecessary since start is called in the testing.core ns ...

tolitius20:03:41

> and a call to that function in the testing.routes.services namespace

tolitius20:03:07

the problem is this is a "global" call to the database on the application start

tolitius20:03:17

i.e. the app should have a chance to start first

tolitius20:03:29

and then you can call a function with a resource

tolitius20:03:17

this line: https://github.com/lucian303/luminus-test/blob/master/src/clj/testing/routes/services.clj#L10 calls into a db before the app ( with all its resources ) is started

tolitius20:03:35

i.e. it is top level, but it should be inside a function

tolitius20:03:00

I also noticed you did not setup db properties:

(!) read config from file: ".lein-env", but it is empty

Exception one of :jdbc-url, :adapter, :datasource, or :datasource-classname is required to initialize the connection!  conman.core/make-config (core.clj:56)

tolitius20:03:10

you can ask about these on the #luminus channel

tolitius20:03:29

as to mount, you can certainly call (db/get-term-names) in REPL or within a function after the initial call to (mount/start)

lucian30320:03:00

@tolitius i updated the code slightly to make the call inside a function (which is how my real code is) but the problem is the same. the repl will not start when i reference anything from the db because the db isn't started by mount

lucian30320:03:10

the db works and i am getting data out of it so there's no need to worry about those calls

lucian30321:03:48

@tolitius i figured out my problem was that the call to the db function should be wrapped in a defstate also so it's not global since it depends on the db (and therefore is a service with state). thanks for your help