From 2bd8d24f5e08213cc3cfd158a3fb55fd74d6c802 Mon Sep 17 00:00:00 2001 From: Artem Medeu Date: Wed, 27 Mar 2024 19:50:24 +0500 Subject: [PATCH 1/2] 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"]}, From 91eedfc3a3eb8aec797c7786dc5dde7d66c433ea Mon Sep 17 00:00:00 2001 From: Artem Medeu Date: Wed, 27 Mar 2024 20:21:28 +0500 Subject: [PATCH 2/2] tests: fix async test --- test/k16/gx/beta/async_processor_test.cljc | 47 ++++++++++------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/test/k16/gx/beta/async_processor_test.cljc b/test/k16/gx/beta/async_processor_test.cljc index 0b5ff2e..e07630b 100644 --- a/test/k16/gx/beta/async_processor_test.cljc +++ b/test/k16/gx/beta/async_processor_test.cljc @@ -20,8 +20,7 @@ (def ^:export my-component-timeout {:gx/start {:gx/processor (fn [{:keys [props]}] - @(p/delay 10000) - props) + (p/do (p/delay 10000) props)) :gx/timeout 10}}) #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} @@ -36,18 +35,12 @@ (defn- run-check [s] (is (= {:foo :bar} - #?(:clj (-> (gx/failures s) - :my-component - :causes - first - :exception - (ex-data)) - :cljs (-> (gx/failures s) - :my-component - :causes - first - :exception - (ex-data)))))) + (-> (gx/failures s) + :my-component + :causes + first + :exception + (ex-data))))) #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} (deftest async-rejected-component-test @@ -66,15 +59,17 @@ (test-async (gx/signal {:graph graph} :gx/start) run-check))) #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} -(deftest async-timeout-component-test - (let [graph {:my-component - {:gx/component - 'k16.gx.beta.async-processor-test/my-component-timeout - :gx/props {:foo :bar}}}] - (is (= "Operation timed out." - (-> @(gx/signal {:graph graph} :gx/start) - (gx/failures) - :my-component - :causes - first - :title))))) +#?(:clj + (deftest async-timeout-component-test + (let [graph {:my-component + {:gx/component + 'k16.gx.beta.async-processor-test/my-component-timeout + :gx/props {:foo :bar}}}] + (is (= "Operation timed out." + (-> @(gx/signal {:graph graph} :gx/start) + (gx/failures) + :my-component + :causes + first + :title)))))) +