Skip to content

Commit

Permalink
fix: do not log from system namespace
Browse files Browse the repository at this point in the history
let lib users decide
  • Loading branch information
armed committed Mar 27, 2024
1 parent 89f17d0 commit 2bd8d24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
1 change: 0 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

:deps
{funcool/promesa {:mvn/version "10.0.594"}
org.clojure/tools.logging {:mvn/version "1.2.4"}
metosin/malli {:mvn/version "0.10.0"}}

:aliases
Expand Down
34 changes: 17 additions & 17 deletions src/k16/gx/beta/system.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns k16.gx.beta.system
(:require [k16.gx.beta.core :as gx]
#?(:clj [clojure.tools.logging :as log])
[k16.gx.beta.errors :as gx.errors]
[promesa.core :as p]))

Expand All @@ -12,21 +11,22 @@
(select-keys graph selector)
graph))

(defn- ->err-msg
[node-key message exception]
(str node-key "\n\t" message (when exception
(str "\n\t" (ex-message exception)))))

(defn throw-root-exception!
[reason-msg failures]
(let [{:keys [message causes node-key] :as f} (last failures)
{:keys [exception]} (first causes)]
(let [msg (str node-key
"\n\t" message
(when exception
(str "\n\t" (ex-message exception))))]
(#?(:clj log/error :cljs js/console.error)
(str reason-msg "\n" (gx.errors/humanize-all failures)))
(throw (or exception (ex-info msg {:failure (last failures)
:subsequent-failures
(-> failures
(butlast)
(reverse))}))))))
[step failures]
(let [{:keys [message causes node-key]} (last failures)
{:keys [exception]} (first causes)
msg (->err-msg node-key message exception)]
(throw (or exception (ex-info msg {:step step
:failure (last failures)
:subsequent-failures
(-> failures
(butlast)
(reverse))})))))

(defn states
"Gets list of states of the graph as map.
Expand Down Expand Up @@ -89,7 +89,7 @@
(let [normalized (gx/normalize gx-map)]
(swap! registry* assoc system-name normalized)
(if-let [failures (seq (:failures normalized))]
(throw-root-exception! "Nomalize error" failures)
(throw-root-exception! :gx/normalize failures)
normalized)))

(defn get-by-name
Expand All @@ -112,7 +112,7 @@
(p/then (fn [graph]
(swap! registry* assoc system-name graph)
(if-let [failures (:failures graph)]
(throw-root-exception! "Signal failed!" failures)
(throw-root-exception! signal-key failures)
graph)))
(p/catch (fn [e] e)))
(p/resolved nil))))
Expand Down
3 changes: 2 additions & 1 deletion test/k16/gx/beta/system_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
:c '(gx/ref :z)}})
(catch ExceptionInfo err
(is (= "\n\tDependency errors" (ex-message err)))
(is (= {:failure {:causes [],
(is (= {:step :gx/normalize
:failure {:causes [],
:error-type :deps-sort,
:internal-data {:errors [":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
Expand Down

0 comments on commit 2bd8d24

Please sign in to comment.