Skip to content

Commit

Permalink
fix: show root failure + subsequent failures in ex-data
Browse files Browse the repository at this point in the history
  • Loading branch information
armed committed Feb 16, 2023
1 parent 53d0263 commit 1c4af0f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 48 deletions.
20 changes: 15 additions & 5 deletions repl_sessions/errors.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
(ns errors
(:require [k16.gx.beta.system :as gx.system]))

(:require
[clojure.edn :as edn]
[k16.gx.beta.system :as gx.system]))

(def server
{:gx/component
{:gx/start {:gx/processor (fn [_] (clojure.edn/read-string
(slurp "repl_sessions/config_with_error.edn")))}
{:gx/start {:gx/processor (fn [_] (edn/read-string
(slurp "repl_sessions/config_with_error.edn")))
:gx/props-schema [:map
[:port :int]
[:secure? :boolean]
[:foo :int]
[:bar :string]]}
:gx/stop {:gx/processor (fn [_] nil)}}})

(def config
{:options {:port 8080
:secure? false}
:server {:gx/component 'errors/server
:gx/props {:foo '(gx/ref :options)}}})
:gx/props '(gx/ref :options)}
:user {:server '(gx/ref :server)}})

(gx.system/register! ::err {:graph config})

@(gx.system/signal! ::err :gx/start)

(println (gx.system/failures-humanized ::err))
(println (gx.system/failures ::err))
32 changes: 16 additions & 16 deletions src/k16/gx/beta/system.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
graph))

(defn throw-root-exception!
[failures]
[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))))]
(throw (or exception (ex-info msg {:failures failures}))))))
(#?(: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))}))))))

(defn states
"Gets list of states of the graph as map.
Expand Down Expand Up @@ -73,9 +79,7 @@
(let [normalized (gx/normalize gx-map)]
(swap! registry* assoc system-name normalized)
(if-let [failures (seq (:failures normalized))]
(do (#?(:clj log/error :cljs js/console.error)
(str "Normalize error\n" (gx.errors/humanize-all failures)))
(throw-root-exception! failures))
(throw-root-exception! "Nomalize error" failures)
normalized)))

(defn get-by-name
Expand All @@ -89,22 +93,18 @@
- Accepts system name and a signal key.
- Returns a promise with a new system on success.
- Returns a resolved promise with nil if system does not exist.
- Clojure: rejects with `clojure.lang.ExceptionInfo` wrapped in
`java.util.concurrent.ExecutionException` on signal failure.
- ClojureScript: rejects with `cljs.core.ExceptionInfo` on signal failure."
- Rejects with `clojure.lang.ExceptionInfo`"
([system-name signal-key]
(signal! system-name signal-key nil))
([system-name signal-key selector]
(if-let [gx-map (get @registry* system-name)]
(-> (gx/signal gx-map signal-key selector)
(p/then (fn [g]
(swap! registry* assoc system-name g)
(if-let [failures (:failures g)]
(do (#?(:clj log/error :cljs js/console.error)
(str "Signal failed!\n"
(gx.errors/humanize-all failures)))
(throw-root-exception! failures))
g))))
(p/then (fn [graph]
(swap! registry* assoc system-name graph)
(if-let [failures (:failures graph)]
(throw-root-exception! "Signal failed!" failures)
graph)))
(p/catch (fn [e] e)))
(p/resolved nil))))

(comment
Expand Down
47 changes: 20 additions & 27 deletions test/k16/gx/beta/system_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,30 @@
:b '(gx/ref :a)
:c '(gx/ref :z)}})
(catch ExceptionInfo err
(is (= {:failures
[{:internal-data
{:errors
[":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
:message "Dependency errors",
(is (= "\n\tDependency errors" (ex-message err)))
(is (= {:failure {:causes [],
:error-type :deps-sort,
:internal-data {:errors [":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
:message "Dependency errors",
:signal-key :gx/stop},
:subsequent-failures
[{:causes [],
:error-type :deps-sort,
:signal-key :gx/start
:causes []}
{:internal-data
{:errors
[":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
:internal-data {:errors [":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
:message "Dependency errors",
:signal-key :gx/resume}
{:causes [],
:error-type :deps-sort,
:signal-key :gx/suspend
:causes []}
{:internal-data
{:errors
[":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
:internal-data {:errors [":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
:message "Dependency errors",
:signal-key :gx/suspend}
{:causes [],
:error-type :deps-sort,
:signal-key :gx/resume
:causes []}
{:internal-data
{:errors
[":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
:internal-data {:errors [":c depends on :z, but :z doesn't exist"
"circular :a -> :b -> :a"]},
:message "Dependency errors",
:error-type :deps-sort,
:signal-key :gx/stop
:causes []}]}
:signal-key :gx/start}]}
(ex-data err))))))

1 comment on commit 1c4af0f

@vercel
Copy link

@vercel vercel bot commented on 1c4af0f Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

gx – ./

gx-git-master-kepler16.vercel.app
gx.kepler16.com
gx-kepler16.vercel.app

Please sign in to comment.