Invocations of `load-string` and/or `js/scittle.core.eval_string` from within a Scittle script lose error context (line and column)
Errors in Scittle scripts are logged with full context (position, code snippet), which is great! (Even so, I found an exception to this rule, w.r.t. unresolvable symbols in the analysis phase, but that's for another issue.)
It would be great if the same quality of error logging, particularly including position info, would be available when invoking load-string or js/scittle.core.eval_string from within a Scittle script (to facilitate an in-browser Clojure(Script) playground), but at the moment that is not the case for both these functions.
So, the following logs an error with informative context:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/scittle.js" type="application/javascript"></script>
<script type="application/x-scittle">
(defn f []
(subs nil 42))
(defn g []
(f))
(g)
</script>
</head>
<body>
</body>
</html>
but the next example does not:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/scittle.js" type="application/javascript"></script>
<script type="application/x-scittle">
(defn try-load-string [s]
(binding [*file* "foo"] ; included per suggestion in Slack, but doesn't yet help getting to the line and column
(try
;;(load-string s)
(js/scittle.core.eval_string s)
(catch :default e
(println "Caught error:" e)
(prn e)
(.log js/console e)))))
(try-load-string "
(defn f []
(subs nil 42))
(defn g []
(f))
(g)
")
</script>
</head>
<body>
</body>
</html>
The aim here is of course to get to the error position within the provided string, not in the context of the Scittle script itself (which is what gets logged when the (try ... (catch ...)) is omitted.