diff --git a/src/darkleaf/di/core.clj b/src/darkleaf/di/core.clj index cbb1549..678555f 100644 --- a/src/darkleaf/di/core.clj +++ b/src/darkleaf/di/core.clj @@ -601,7 +601,8 @@ (defn- check-nil-component! [component var] (if (nil? component) - (throw (ex-info (str "nil component " var) {})) + (throw (ex-info (str "nil component " var) + {:type ::nil-component})) component)) (defn- var->0-component [variable] diff --git a/test/darkleaf/di/component_test.clj b/test/darkleaf/di/component_test.clj index ad3cb46..367b522 100644 --- a/test/darkleaf/di/component_test.clj +++ b/test/darkleaf/di/component_test.clj @@ -5,13 +5,25 @@ (:import (clojure.lang ExceptionInfo))) +(defmacro catch-cause-data [& body] + `(try ~@body + (catch clojure.lang.ExceptionInfo e# + (mapv :data (:via (Throwable->map e#)))))) + (defn nil-component {::di/kind :component} [] nil) +(defn nil-component-1-arity + {::di/kind :component} + [_] + nil) + (t/deftest nil-component-test - (t/is (thrown-with-msg? - ExceptionInfo - #"\Anil component #'darkleaf.di.component-test/nil-component\z" - (di/start `nil-component)))) + (t/is (= [{:stack [`nil-component ::di/implicit-root]} + {:type ::di/nil-component}] + (catch-cause-data (di/start `nil-component)))) + (t/is (= [{:stack [`nil-component-1-arity ::di/implicit-root]} + {:type ::di/nil-component}] + (catch-cause-data (di/start `nil-component-1-arity)))))