Skip to content

Commit

Permalink
handle errors in client
Browse files Browse the repository at this point in the history
  • Loading branch information
pbaille committed Dec 12, 2024
1 parent e435dd3 commit 681cc23
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
11 changes: 6 additions & 5 deletions client/noon/client/eval.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
[noon.lib.rythmn]
[noon.utils.misc]
[sci.core :as sci]
[noon.client.sci-macros :as sci-macros])
[noon.client.sci-macros])
(:require-macros [noon.client.eval :refer [sci-namespace]]))

(def sci-ctx
(sci/init
{:namespaces {'user (merge (sci-namespace noon.updates)
sci-macros/all
(ns-publics 'noon.client.sci-macros)
{'mk #'noon.score/mk})
'noon.output (ns-publics 'noon.output)
'noon.score (sci-namespace noon.score)
Expand All @@ -32,9 +32,10 @@
#_ (println sci-ctx)
(defn sci-eval [x]
#_(println sci-ctx)
(let [ret (sci/eval-string* sci-ctx x)]
(println "evaluated " ret)
ret))
(let [evaluation (try {:result (sci/eval-string* sci-ctx x)}
(catch js/Error e {:error e}))]
(println (assoc evaluation :form x))
evaluation))

(comment
(println "ui")
Expand Down
12 changes: 10 additions & 2 deletions client/noon/client/sci_macros.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@
[_ _ & xs]
`(noon.output/play-score (noon.score/mk ~@xs)))

(def all
(defn noon
{:sci/macro true}
[_ _ opts score]
`(do ~@(when (:play opts) [`(noon.output/play-score ~score)])
~@(when-let [unsupported-keys (seq (keys (dissoc opts :play)))]
[`(throw (js/Error. ~(str "Not supported noon options: " unsupported-keys)))])))

#_(def all
{'sf_ #'sf_ 'sfn #'sfn
'ef_ #'ef_ 'efn #'efn
'! #'!
'play #'play})
'play #'play
'noon #'noon})
8 changes: 5 additions & 3 deletions client/noon/client/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
:bg {:color [color {:a 0.2}]}
:color [color {:l 0.5}]
:p 1}
:on-click (fn [_] (set-return (str (eval/sci-eval source))))}
:on-click (fn [_] (set-return (eval/sci-eval source)))}
(c icons/VscDebugLineByLine)))
(when return
(sc {:border [2 [color {:a 0.2}]]
(sc {:bg {:color (if (:error return) [:red {:a 0.2}] [color {:a 0.2}])}
:border [2 [color {:a 0.2}]]
:p [0.3 0.7]}
(c CodeMirror
{:value return
{:value (str (or (:error return)
(:result return)))
:editable false
:extensions #js [(clojure)]
:basic-setup #js {:lineNumbers false
Expand Down

0 comments on commit 681cc23

Please sign in to comment.