Skip to content

Commit

Permalink
wrap exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Dec 17, 2024
1 parent 5ba6f77 commit d8c302b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,18 @@
:declared-deps deps
:remaining-deps (seq deps)}))

(defn- build-obj [built-map head]
(let [factory (:factory head)
(defn- build-obj [built-map stack]
(let [head (peek stack)
factory (:factory head)
declared-deps (:declared-deps head)
built-deps (select-keys built-map (keys declared-deps))]
(p/build factory built-deps)))
(try
(p/build factory built-deps)
(catch RuntimeException ex
(throw (ex-info "An error during component start"
{:stack (map :key stack)}
ex))))))


(defn- build [{:keys [registry *stop-list]} key]
(loop [stack (list (stack-frame key :required (registry key)))
Expand Down Expand Up @@ -126,7 +133,7 @@
built-map))

:else
(let [obj (build-obj built-map head)
(let [obj (build-obj built-map stack)
stop #(p/demolish factory obj)]
(vswap! *stop-list conj stop)
(case [obj dep-type]
Expand Down

0 comments on commit d8c302b

Please sign in to comment.