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/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)))))) + 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"]},