sci

2023-01-13T20:48:00.328149Z

Iโ€™m trying to display errors in a nice way and in simple cases this works by using line and col info of the exception but when something is wrapped in a macro this information seems to be lost. Iโ€™ve seen this in Sci, but I โ€™ve seen it in Babashka too. I wonder if this can be fixed. ๐Ÿงต

2023-01-16T16:21:48.294979Z

I think everything works as expected now. Had some other issue to solve before i could verify properly ๐Ÿ˜…

๐ŸŽ‰ 1
2023-01-13T20:48:19.559079Z

โžœ  ~ bb -e 'foo'
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: foo
Location: <expr>:1:1
Phase:    analysis

----- Context ------------------------------------------------------------------
1: foo
   ^--- Could not resolve symbol: foo

โžœ  ~ bb -e '(defmacro bar [& body] `(do ~@body)) (bar foo)'
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: foo
Phase:    analysis

2023-01-13T20:48:58.681219Z

(sci/eval-string "foo")
clojure.lang.ExceptionInfo: Could not resolve symbol: foo
{:type :sci/error, :line 1, :column 1, :file nil, :phase "analysis"}
vs
(sci/eval-string "(do (defmacro a-macro [& body] `(do ~@body)) (a-macro foo))")
clojure.lang.ExceptionInfo: Could not resolve symbol: foo
{:type :sci/error, :line nil, :column nil, :file nil, :phase "analysis"}

2023-01-13T20:56:17.774719Z

In clojure

โžœ  ~ clj -e '(defmacro bar [& body] `(do ~@body)) (bar foo)'
WARNING: Implicit use of clojure.main with options is deprecated, use -M
#'user/bar
Syntax error compiling at (REPL:1:38).
Unable to resolve symbol: foo in this context

2023-01-13T21:06:50.349339Z

Iโ€™m guessing this issue is related https://github.com/babashka/sci/issues/775

borkdude 2023-01-13T21:20:27.006219Z

There have been various improvement in this area after people posted an issue about it - welcome to do it again! :) The 775 issue isn't related

borkdude 2023-01-13T21:23:38.478949Z

Note that when you wrap (bar foo) with a vector or so, the error report gives a decent location. I think the issue can be solved

2023-01-13T21:37:21.715339Z

Ah cool, Iโ€™ll try that

2023-01-13T21:38:13.754839Z

Iโ€™ll create an issue later ๐Ÿ˜…

2023-01-13T21:38:36.900959Z

Thanks and have a good night & weekend!

borkdude 2023-01-13T21:43:21.614739Z

I'm on a train ride now, I'll look into it now, thanks for giving me something to do ;)

2023-01-13T21:45:37.095269Z

haha youโ€™re welcome ๐Ÿ’ช

2023-01-13T21:45:59.576239Z

wrapping it with a vector works and helps me further for now!

bb -e '[ (defmacro bar [& body] `(do ~@body)) (bar foo)]'
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: foo
Data:     {:type :sci/error, :line nil, :column nil, :file "<expr>", :phase "analysis"}
Location: <expr>:1:40
Phase:    analysis

----- Context ------------------------------------------------------------------
1: [ (defmacro bar [& body] `(do ~@body)) (bar foo)]
                                          ^--- Could not resolve symbol: foo

----- Stack trace --------------------------------------------------------------
user - <expr>:1:40

borkdude 2023-01-13T22:23:26.606429Z

Nearing the end of my train ride. I fixed it in SCI branch fix-top-level-macro-error-loc I think. Need to add a test for it, but with babashka I now get error locations

๐Ÿ™Œ 1
borkdude 2023-01-13T22:23:56.762679Z

Still welcome to post an issue in case I forget about this branch ๐Ÿ˜…

borkdude 2023-01-14T09:59:40.798819Z

OK, pushed the improvement to SCI and bb

borkdude 2023-01-14T10:00:12.210819Z

When the master build finishes you can obtain the new bb with:

bash <(curl ) --dev-build --dir /tmp

2023-01-14T12:59:36.442239Z

Thank you so much! Iโ€™ll test it properly in the coming days. The master build works for me.

/tmp/bb -e '(defmacro bar [& body] `(do ~@body)) (bar (bar :aaa (let [a 1 b 2 c 4 c 5] foo)))'
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: foo
Data:     {:type :sci/error, :line 1, :column 53, :file "<expr>", :phase "analysis"}
Location: <expr>:1:53
Phase:    analysis

----- Context ------------------------------------------------------------------
1: (defmacro bar [& body] `(do ~@body)) (bar (bar :aaa (let [a 1 b 2 c 4 c 5] foo)))
                                                       ^--- Could not resolve symbol: foo
This feedback is a huge improvement! Iโ€™ll check in my own code later

borkdude 2023-01-14T15:34:52.297939Z

That example already worked well with bb 1.0.169, but this example didn't:

-e '(defmacro bar [& body] `(do ~@body)) (bar foo)'

2023-01-14T18:20:13.855279Z

Ah ok. I saw the line and col were pointing to the wrapping macro and not exactly to foo. So I was nesting it in order to see what would happen. Didn't realize this was a different case that was already working