From 2bd8d24f5e08213cc3cfd158a3fb55fd74d6c802 Mon Sep 17 00:00:00 2001 From: Artem Medeu Date: Wed, 27 Mar 2024 19:50:24 +0500 Subject: [PATCH] fix: do not log from system namespace let lib users decide --- deps.edn | 1 - src/k16/gx/beta/system.cljc | 34 +++++++++++++++---------------- test/k16/gx/beta/system_test.cljc | 3 ++- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/deps.edn b/deps.edn index 6b67e26..8d767b6 100644 --- a/deps.edn +++ b/deps.edn @@ -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 diff --git a/src/k16/gx/beta/system.cljc b/src/k16/gx/beta/system.cljc index 32998e6..8864b0d 100644 --- a/src/k16/gx/beta/system.cljc +++ b/src/k16/gx/beta/system.cljc @@ -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])) @@ -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. @@ -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 @@ -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)))) diff --git a/test/k16/gx/beta/system_test.cljc b/test/k16/gx/beta/system_test.cljc index 3cc57de..d8dd2c2 100644 --- a/test/k16/gx/beta/system_test.cljc +++ b/test/k16/gx/beta/system_test.cljc @@ -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"]},