Skip to content

Commit

Permalink
Merge pull request #24 from kepler16/fix/supress-system-error-logs
Browse files Browse the repository at this point in the history
fix: suppress system error logs
  • Loading branch information
armed authored Mar 27, 2024
2 parents 89f17d0 + 91eedfc commit 693fa8c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 45 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
47 changes: 21 additions & 26 deletions test/k16/gx/beta/async_processor_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
Expand All @@ -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
Expand All @@ -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))))))

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 693fa8c

Please sign in to comment.