Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle ex #24

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,16 @@
[nil :required] (missing-dependency! stack)
(recur tail (assoc built-map key obj)))))))))

(defn- try-run [proc]
(defn- handle-ex [proc handler]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KGOH @krevedkokun it seems ugly for me. Do you know any other solution?
In Java we should not catch Errors, but in Clojure I want to catch and recover on AssertionError.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(defn- try-run [proc]
  (try (proc)
       nil
       (catch Exception e e)
       (catch AssertionError e e)))

(defn- try-build [ctx key]
  (try (build ctx key)
       (catch Exception e e (??? e))
       (catch AssertionError e e (??? e))))

(try
(proc)
nil
(catch Throwable ex
ex)))
(catch Exception ex
(handler ex))
(catch AssertionError ex
(handler ex))))

(defn- try-run [proc]
(handle-ex #(do (proc) nil) identity))

(defn- try-run-all [procs]
(->> procs
Expand All @@ -155,13 +159,13 @@
(vswap! *stop-list empty)
(try-run-all stops)))

(defn- try-build-catch [ex ctx])

(defn- try-build [ctx key]
(try
(build ctx key)
(catch Throwable ex
(let [exs (try-stop-started ctx)
exs (cons ex exs)]
(throw-many! exs)))))
(handle-ex #(build ctx key)
#(let [exs (try-stop-started ctx)
exs (cons % exs)]
(throw-many! exs))))

(defn- nil-registry [key]
nil)
Expand Down
Loading