better location info in error, #33
This commit is contained in:
parent
f4b10bc46c
commit
ef34e84e59
|
@ -5,18 +5,22 @@
|
||||||
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
|
<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 src="../js/scittle.reagent.js" type="application/javascript"></script>
|
||||||
<script type="application/x-scittle">
|
<script type="application/x-scittle">
|
||||||
(require '[reagent.core :as r]
|
(require '[sci.core :as sci])
|
||||||
'[reagent.dom :as rdom])
|
(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 []
|
(defn g []
|
||||||
[:div
|
(f))
|
||||||
[: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!"]]])
|
|
||||||
|
|
||||||
(rdom/render [my-component] (.getElementById js/document "app"))
|
(g)
|
||||||
|
")
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -30,7 +30,9 @@
|
||||||
'random-uuid random-uuid
|
'random-uuid random-uuid
|
||||||
'read-string (sci/copy-var read-string rns)}
|
'read-string (sci/copy-var read-string rns)}
|
||||||
'goog.object {'set gobject/set
|
'goog.object {'set gobject/set
|
||||||
'get gobject/get}})
|
'get gobject/get}
|
||||||
|
'sci.core {'stacktrace sci/stacktrace
|
||||||
|
'format-stacktrace sci/format-stacktrace}})
|
||||||
|
|
||||||
(def !sci-ctx
|
(def !sci-ctx
|
||||||
(atom (sci/init {:namespaces namespaces
|
(atom (sci/init {:namespaces namespaces
|
||||||
|
@ -56,10 +58,7 @@
|
||||||
(try (-eval-string s)
|
(try (-eval-string s)
|
||||||
(catch :default e
|
(catch :default e
|
||||||
(error/error-handler e (:src @!sci-ctx))
|
(error/error-handler e (:src @!sci-ctx))
|
||||||
(let [sci-error? (isa? (:type (ex-data e)) :sci/error)]
|
(throw e))))
|
||||||
(throw (if sci-error?
|
|
||||||
(or (ex-cause e) e)
|
|
||||||
e))))))
|
|
||||||
|
|
||||||
(defn register-plugin! [plug-in-name sci-opts]
|
(defn register-plugin! [plug-in-name sci-opts]
|
||||||
plug-in-name ;; unused for now
|
plug-in-name ;; unused for now
|
||||||
|
|
Loading…
Reference in a new issue