duct

erwinrooijakkers 2020-07-15T11:30:35.260700Z

I have a following config:

erwinrooijakkers 2020-07-15T11:31:58.261700Z

{:duct.profile/base
 {:update-organization
  {:organization-client #ig/ref :client}

  :fetch-organization
  {:organization-client #ig/ref :client}

  :client {}

erwinrooijakkers 2020-07-15T11:33:06.262800Z

Where client is an instantation of a deftype:

(defmethod ig/init-key :client
  [_ opts]
  (log/info ::client {:opts opts})
  (->OrganizationClient))

erwinrooijakkers 2020-07-15T11:33:53.263300Z

This throws the following error:

13:33:21.229 INFO :client {:opts {}}
Execution error (ClassCastException) at duct.core/fold-modules$fn (core.clj:153).
OrganizationClient cannot be cast to clojure.lang.IFn

erwinrooijakkers 2020-07-15T11:33:55.263500Z

Any idea why?

erwinrooijakkers 2020-07-15T11:49:17.263800Z

Stacktrace:

1. Unhandled java.lang.ClassCastException
   OrganizationClient cannot be cast to clojure.lang.IFn

                  core.clj:  153  duct.core/fold-modules/fn
                 core.cljc:  280  integrant.core$fold$fn__857/invoke
             ArraySeq.java:  116  clojure.lang.ArraySeq/reduce
                  core.clj: 6827  clojure.core/reduce
                  core.clj: 6810  clojure.core/reduce
                 core.cljc:  280  integrant.core$fold/invokeStatic
                 core.cljc:  272  integrant.core$fold/invoke
                  core.clj:  153  duct.core/fold-modules
                  core.clj:  147  duct.core/fold-modules
                  core.clj:  190  duct.core/build-config
                  core.clj:  181  duct.core/build-config
                  core.clj:  201  duct.core/prep-config
                  core.clj:  192  duct.core/prep-config
                   dev.clj:   31  dev/eval19069/fn
                  repl.clj:   16  integrant.repl/prep/fn
                  AFn.java:  154  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  Var.java:  308  clojure.lang.Var/alterRoot
                  core.clj: 5510  clojure.core/alter-var-root
                  core.clj: 5505  clojure.core/alter-var-root
               RestFn.java:  425  clojure.lang.RestFn/invoke
                  repl.clj:   16  integrant.repl/prep
                  repl.clj:   14  integrant.repl/prep
                  repl.clj:   54  integrant.repl/go
                  repl.clj:   53  integrant.repl/go
                      REPL:  484  dev/eval26347
                      REPL:  484  dev/eval26347
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7132  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
    interruptible_eval.clj:   82  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   82  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj:  660  clojure.core/apply
                regrow.clj:   20  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  145  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  202  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  201  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  748  java.lang.Thread/run

kwrooijen 2020-07-15T11:52:10.264400Z

Being cast to fn probably means that there is a non module key outside of the base config

1🔥
teodorlu 2020-07-16T11:33:52.267500Z

I came in to ask about just a duct.database.sql.Boundary cannot be cast to class clojure.lang.IFn -- I had put keys outside of the base config. Thanks! I guess config validation error messages might be happy to receive some love ...

kwrooijen 2020-07-16T15:12:54.267700Z

Thanks for reminding me. I still need to implement a test for this PR https://github.com/duct-framework/core/pull/32

kwrooijen 2020-07-16T15:13:03.268Z

This PR addresses this exact issue 🙂

kwrooijen 2020-07-16T15:13:31.268200Z

I'll see if I can whip something up tonight

1💯
kwrooijen 2020-07-15T11:54:32.265700Z

The error is occurring in the fold modules function. Which verifies that

erwinrooijakkers 2020-07-15T12:04:19.266Z

Oh okay so some keys should be outside the base config?

erwinrooijakkers 2020-07-15T12:04:25.266200Z

Like the :client

erwinrooijakkers 2020-07-15T12:04:59.267Z

Oh inside

kwrooijen 2020-07-15T12:06:49.267300Z

Only module keys should be outside of the base config