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. ๐งต
I think everything works as expected now. Had some other issue to solve before i could verify properly ๐
โ ~ 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(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"}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 contextIโm guessing this issue is related https://github.com/babashka/sci/issues/775
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
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
Ah cool, Iโll try that
Iโll create an issue later ๐
Thanks and have a good night & weekend!
I'm on a train ride now, I'll look into it now, thanks for giving me something to do ;)
haha youโre welcome ๐ช
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:40Nearing 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
Still welcome to post an issue in case I forget about this branch ๐
OK, pushed the improvement to SCI and bb
When the master build finishes you can obtain the new bb with:
bash <(curl ) --dev-build --dir /tmp 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 laterThat example already worked well with bb 1.0.169, but this example didn't:
-e '(defmacro bar [& body] `(do ~@body)) (bar foo)'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