Fork me on GitHub
#sci
<
2023-01-13
>
jeroenvandijk20:01:00

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. 🧵

jeroenvandijk20:01:19

➜  ~ 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

jeroenvandijk20:01:58

(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"}

jeroenvandijk20:01:17

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

borkdude21:01:27

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

borkdude21:01:38

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

jeroenvandijk21:01:21

Ah cool, I’ll try that

jeroenvandijk21:01:13

I’ll create an issue later 😅

jeroenvandijk21:01:36

Thanks and have a good night & weekend!

borkdude21:01:21

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

jeroenvandijk21:01:37

haha you’re welcome 💪

jeroenvandijk21:01:59

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

borkdude22:01:26

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

🙌 2
borkdude22:01:56

Still welcome to post an issue in case I forget about this branch 😅

borkdude09:01:40

OK, pushed the improvement to SCI and bb

borkdude10:01:12

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

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

jeroenvandijk12:01:36

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

borkdude15:01:52

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

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

jeroenvandijk18:01:13

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

jeroenvandijk16:01:48

I think everything works as expected now. Had some other issue to solve before i could verify properly 😅

🎉 2