Skip to content

Instantly share code, notes, and snippets.

@vvvvalvalval
Last active Apr 10, 2018
Embed
What would you like to do?
(ns dev
(:refer-clojure :exclude [test])
(:require [clojure.repl :refer :all]
[fipp.edn :refer [pprint]]
[clojure.tools.namespace.repl :refer [refresh]]
[clojure.java.io :as io]
[duct.core :as duct]
[duct.core.repl :as duct-repl]
[duct.repl.figwheel :refer [cljs-repl]]
[eftest.runner :as eftest]
[integrant.core :as ig]
[integrant.repl :refer [clear halt go init prep reset]]
[integrant.repl.state :refer [config system]]))
(duct/load-hierarchy)
(defn read-config []
(duct/read-config (io/resource "repro-config.edn")))
(integrant.repl/set-prep! (comp duct/prep read-config))
;; [...] other Duct dev stuff
(require 'compojure.core)
(derive :debug/root-handler :duct.core/handler)
(derive :debug/site-handler :duct.core/handler)
(derive :debug/api-handler :duct.core/handler)
(defn handler1
[req]
(prn req)
{:body "handler1"})
(defmethod ig/init-key :leaf-handler1
[_ opts]
(println "init" :leaf-handler1)
(compojure.core/GET "/handler1" req
(handler1 req)))
(defn handler2
[req]
(prn req)
{:body "handler2"})
(defmethod ig/init-key :leaf-handler2
[_ opts]
(println "init" :leaf-handler2)
(compojure.core/GET "/handler2" req
(handler2 req)))
(comment
(go)
;init :leaf-handler2
;init :leaf-handler1
;ExceptionInfo Ambiguous key: :duct.core/handler. Found multiple candidates: :debug/site-handler, :debug/root-handler, :debug/api-handler clojure.core/ex-info (core.clj:4739)
*e
;=>
#error{:cause "Ambiguous key: :duct.core/handler. Found multiple candidates: :debug/site-handler, :debug/root-handler, :debug/api-handler",
:data {:reason :integrant.core/ambiguous-key,
:config {:leaf-handler2 {},
:duct.handler.static/method-not-allowed {:headers {"Content-Type" "text/plain; charset=UTF-8"},
:body "Method Not Allowed"},
:duct.logger/timbre {:level :debug,
:appenders #:duct.logger.timbre{:spit #integrant.core.Ref{:key :duct.logger.timbre/spit},
:brief #integrant.core.Ref{:key :duct.logger.timbre/brief}}},
:duct.logger.timbre/brief {:min-level :report},
:duct.middleware.web/log-requests {:logger #integrant.core.Ref{:key :duct/logger}},
:debug/site-handler {:middleware [#integrant.core.Ref{:key :duct.middleware.web/not-found}
#integrant.core.Ref{:key :duct.middleware.web/defaults}
#integrant.core.Ref{:key :duct.middleware.web/log-requests}
#integrant.core.Ref{:key :duct.middleware.web/log-errors}
#integrant.core.Ref{:key :duct.middleware.web/stacktrace}],
:router #integrant.core.Ref{:key :leaf-handler1}},
:debug/root-handler {:middleware [#integrant.core.Ref{:key :duct.middleware.web/not-found}
#integrant.core.Ref{:key :duct.middleware.web/defaults}
#integrant.core.Ref{:key :duct.middleware.web/log-requests}
#integrant.core.Ref{:key :duct.middleware.web/log-errors}
#integrant.core.Ref{:key :duct.middleware.web/stacktrace}],
:router #integrant.core.Ref{:key :duct.router/cascading}},
:duct.middleware.web/defaults {:params {:urlencoded true, :keywordize true},
:responses {:not-modified-responses true,
:absolute-redirects true,
:content-types true,
:default-charset "utf-8"}},
:duct.server.http/jetty {:port 3000,
:handler #integrant.core.Ref{:key :duct.core/handler},
:logger #integrant.core.Ref{:key :duct/logger}},
:duct.handler.static/internal-server-error {:headers {"Content-Type" "text/plain; charset=UTF-8"},
:body "Internal Server Error"},
:duct.middleware.web/hide-errors {:error-handler #integrant.core.Ref{:key :duct.handler.static/internal-server-error}},
:duct.logger.timbre/spit {:fname "logs/dev.log"},
:duct.middleware.web/log-errors {:logger #integrant.core.Ref{:key :duct/logger}},
:duct.handler.static/not-found {:headers {"Content-Type" "text/plain; charset=UTF-8"},
:body "Not Found"},
:leaf-handler1 {},
:duct.router/cascading [#integrant.core.Ref{:key :debug/site-handler}
#integrant.core.Ref{:key :debug/api-handler}],
:duct.module/web {:handler #integrant.core.Ref{:key :debug/root-handler}},
:duct.middleware.web/not-found {:error-handler #integrant.core.Ref{:key :duct.handler.static/not-found}},
:debug/api-handler {:middleware [#integrant.core.Ref{:key :duct.middleware.web/not-found}
#integrant.core.Ref{:key :duct.middleware.web/defaults}
#integrant.core.Ref{:key :duct.middleware.web/log-requests}
#integrant.core.Ref{:key :duct.middleware.web/log-errors}
#integrant.core.Ref{:key :duct.middleware.web/stacktrace}],
:router #integrant.core.Ref{:key :leaf-handler2}},
:duct.core/environment :development,
:duct.module/logging {},
:duct.middleware.web/stacktrace {},
:duct.handler.static/bad-request {:headers {"Content-Type" "text/plain; charset=UTF-8"},
:body "Bad Request"},
:duct.core/project-ns site-cljs-example},
:key :duct.core/handler,
:matching-keys (:debug/site-handler :debug/root-handler :debug/api-handler)},
:via [{:type clojure.lang.ExceptionInfo,
:message "Ambiguous key: :duct.core/handler. Found multiple candidates: :debug/site-handler, :debug/root-handler, :debug/api-handler",
:data {:reason :integrant.core/ambiguous-key,
:config {:leaf-handler2 {},
:duct.handler.static/method-not-allowed {:headers {"Content-Type" "text/plain; charset=UTF-8"},
:body "Method Not Allowed"},
:duct.logger/timbre {:level :debug,
:appenders #:duct.logger.timbre{:spit #integrant.core.Ref{:key :duct.logger.timbre/spit},
:brief #integrant.core.Ref{:key :duct.logger.timbre/brief}}},
:duct.logger.timbre/brief {:min-level :report},
:duct.middleware.web/log-requests {:logger #integrant.core.Ref{:key :duct/logger}},
:debug/site-handler {:middleware [#integrant.core.Ref{:key :duct.middleware.web/not-found}
#integrant.core.Ref{:key :duct.middleware.web/defaults}
#integrant.core.Ref{:key :duct.middleware.web/log-requests}
#integrant.core.Ref{:key :duct.middleware.web/log-errors}
#integrant.core.Ref{:key :duct.middleware.web/stacktrace}],
:router #integrant.core.Ref{:key :leaf-handler1}},
:debug/root-handler {:middleware [#integrant.core.Ref{:key :duct.middleware.web/not-found}
#integrant.core.Ref{:key :duct.middleware.web/defaults}
#integrant.core.Ref{:key :duct.middleware.web/log-requests}
#integrant.core.Ref{:key :duct.middleware.web/log-errors}
#integrant.core.Ref{:key :duct.middleware.web/stacktrace}],
:router #integrant.core.Ref{:key :duct.router/cascading}},
:duct.middleware.web/defaults {:params {:urlencoded true, :keywordize true},
:responses {:not-modified-responses true,
:absolute-redirects true,
:content-types true,
:default-charset "utf-8"}},
:duct.server.http/jetty {:port 3000,
:handler #integrant.core.Ref{:key :duct.core/handler},
:logger #integrant.core.Ref{:key :duct/logger}},
:duct.handler.static/internal-server-error {:headers {"Content-Type" "text/plain; charset=UTF-8"},
:body "Internal Server Error"},
:duct.middleware.web/hide-errors {:error-handler #integrant.core.Ref{:key :duct.handler.static/internal-server-error}},
:duct.logger.timbre/spit {:fname "logs/dev.log"},
:duct.middleware.web/log-errors {:logger #integrant.core.Ref{:key :duct/logger}},
:duct.handler.static/not-found {:headers {"Content-Type" "text/plain; charset=UTF-8"},
:body "Not Found"},
:leaf-handler1 {},
:duct.router/cascading [#integrant.core.Ref{:key :debug/site-handler}
#integrant.core.Ref{:key :debug/api-handler}],
:duct.module/web {:handler #integrant.core.Ref{:key :debug/root-handler}},
:duct.middleware.web/not-found {:error-handler #integrant.core.Ref{:key :duct.handler.static/not-found}},
:debug/api-handler {:middleware [#integrant.core.Ref{:key :duct.middleware.web/not-found}
#integrant.core.Ref{:key :duct.middleware.web/defaults}
#integrant.core.Ref{:key :duct.middleware.web/log-requests}
#integrant.core.Ref{:key :duct.middleware.web/log-errors}
#integrant.core.Ref{:key :duct.middleware.web/stacktrace}],
:router #integrant.core.Ref{:key :leaf-handler2}},
:duct.core/environment :development,
:duct.module/logging {},
:duct.middleware.web/stacktrace {},
:duct.handler.static/bad-request {:headers {"Content-Type" "text/plain; charset=UTF-8"},
:body "Bad Request"},
:duct.core/project-ns site-cljs-example},
:key :duct.core/handler,
:matching-keys (:debug/site-handler :debug/root-handler :debug/api-handler)},
:at [clojure.core$ex_info invokeStatic "core.clj" 4739]}],
:trace [[clojure.core$ex_info invokeStatic "core.clj" 4739]
[clojure.core$ex_info invoke "core.clj" 4739]
[integrant.core$ambiguous_key_exception invokeStatic "core.cljc" 46]
[integrant.core$ambiguous_key_exception invoke "core.cljc" 45]
[integrant.core$build invokeStatic "core.cljc" 237]
[integrant.core$build invoke "core.cljc" 224]
[integrant.core$init invokeStatic "core.cljc" 317]
[integrant.core$init invoke "core.cljc" 309]
[integrant.core$init invokeStatic "core.cljc" 314]
[integrant.core$init invoke "core.cljc" 309]
[integrant.repl$init$fn__35884 invoke "repl.clj" 21]
[clojure.lang.AFn applyToHelper "AFn.java" 154]
[clojure.lang.AFn applyTo "AFn.java" 144]
[clojure.lang.Var alterRoot "Var.java" 305]
[clojure.core$alter_var_root invokeStatic "core.clj" 5450]
[clojure.core$alter_var_root doInvoke "core.clj" 5445]
[clojure.lang.RestFn invoke "RestFn.java" 425]
[integrant.repl$init invokeStatic "repl.clj" 21]
[integrant.repl$init invoke "repl.clj" 20]
[integrant.repl$go invokeStatic "repl.clj" 26]
[integrant.repl$go invoke "repl.clj" 24]
[dev$eval43198 invokeStatic "form-init2612792741243851315.clj" 1]
[dev$eval43198 invoke "form-init2612792741243851315.clj" 1]
[clojure.lang.Compiler eval "Compiler.java" 7062]
[clojure.lang.Compiler eval "Compiler.java" 7025]
[clojure.core$eval invokeStatic "core.clj" 3206]
[clojure.core$eval invoke "core.clj" 3202]
[clojure.main$repl$read_eval_print__8572$fn__8575 invoke "main.clj" 243]
[clojure.main$repl$read_eval_print__8572 invoke "main.clj" 243]
[clojure.main$repl$fn__8581 invoke "main.clj" 261]
[clojure.main$repl invokeStatic "main.clj" 261]
[clojure.main$repl doInvoke "main.clj" 177]
[clojure.lang.RestFn invoke "RestFn.java" 1523]
[clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__838 invoke "interruptible_eval.clj" 87]
[clojure.lang.AFn applyToHelper "AFn.java" 152]
[clojure.lang.AFn applyTo "AFn.java" 144]
[clojure.core$apply invokeStatic "core.clj" 657]
[clojure.core$with_bindings_STAR_ invokeStatic "core.clj" 1965]
[clojure.core$with_bindings_STAR_ doInvoke "core.clj" 1965]
[clojure.lang.RestFn invoke "RestFn.java" 425]
[clojure.tools.nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 85]
[clojure.tools.nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 55]
[clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__883$fn__886
invoke
"interruptible_eval.clj"
222]
[clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__878 invoke "interruptible_eval.clj" 190]
[clojure.lang.AFn run "AFn.java" 22]
[java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1149]
[java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 624]
[java.lang.Thread run "Thread.java" 748]]}
)
{:duct.core/project-ns site-cljs-example
:duct.core/environment :development
:duct.module/logging {}
#_:duct.module.web/site
:duct.module/web
{:handler #ig/ref :debug/root-handler}
:duct.router/cascading
[#ig/ref :debug/site-handler
#ig/ref :debug/api-handler]
:debug/root-handler
{:middleware []
:router #ig/ref :duct.router/cascading}
:debug/site-handler
{:middleware []
:router #ig/ref :leaf-handler1}
:debug/api-handler
{:middleware []
:router #ig/ref :leaf-handler2}
:leaf-handler1 {}
:leaf-handler2 {}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment