better location info in error, #33

This commit is contained in:
Michiel Borkent 2022-08-31 14:07:01 +02:00
parent f4b10bc46c
commit ef34e84e59
2 changed files with 17 additions and 14 deletions

View file

@ -5,18 +5,22 @@
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="../js/scittle.reagent.js" type="application/javascript"></script>
<script type="application/x-scittle">
(require '[reagent.core :as r]
'[reagent.dom :as rdom])
(require '[sci.core :as sci])
(defn try-load-string [s]
(try
(js/scittle.core.eval_string s)
(catch ^:sci/error js/Error e
(run! println (-> (sci/stacktrace e) (sci/format-stacktrace))))))
(def state (r/atom {:clicks 0}))
(try-load-string "
(defn f []
(subs nil 42))
(defn my-component []
[:div
[:p "Clicks: " (:clicks @state)]
[:p [:button {:on-click #(do (print :foo) (println :dude) (prn (with-out-str (prn :foo))) (swap! state update :clicks inc))}
"Click me!"]]])
(defn g []
(f))
(rdom/render [my-component] (.getElementById js/document "app"))
(g)
")
</script>
</head>
<body>

View file

@ -30,7 +30,9 @@
'random-uuid random-uuid
'read-string (sci/copy-var read-string rns)}
'goog.object {'set gobject/set
'get gobject/get}})
'get gobject/get}
'sci.core {'stacktrace sci/stacktrace
'format-stacktrace sci/format-stacktrace}})
(def !sci-ctx
(atom (sci/init {:namespaces namespaces
@ -56,10 +58,7 @@
(try (-eval-string s)
(catch :default e
(error/error-handler e (:src @!sci-ctx))
(let [sci-error? (isa? (:type (ex-data e)) :sci/error)]
(throw (if sci-error?
(or (ex-cause e) e)
e))))))
(throw e))))
(defn register-plugin! [plug-in-name sci-opts]
plug-in-name ;; unused for now