This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-19
Channels
- # announcements (4)
- # asami (1)
- # babashka (48)
- # beginners (84)
- # bristol-clojurians (1)
- # calva (15)
- # chlorine-clover (11)
- # cider (37)
- # clj-kondo (17)
- # clojure (72)
- # clojure-europe (13)
- # clojure-italy (43)
- # clojure-nl (6)
- # clojure-spec (8)
- # clojure-uk (19)
- # clojuredesign-podcast (7)
- # clojurescript (132)
- # code-reviews (7)
- # conjure (3)
- # cursive (24)
- # datascript (10)
- # datomic (61)
- # docker (4)
- # duct (24)
- # emacs (2)
- # figwheel-main (8)
- # fulcro (43)
- # graalvm (5)
- # juxt (1)
- # keechma (14)
- # malli (2)
- # off-topic (120)
- # re-frame (111)
- # reagent (6)
- # reitit (13)
- # shadow-cljs (118)
- # spacemacs (3)
- # tools-deps (32)
- # uncomplicate (5)
- # xtdb (6)
Hi folks, I'm having some trouble using babashka pods
I'm running bb --classpath \"(clojure -Spath)\" -f src/site/build.clj
(using fish shell)
my deps.edn
{:deps
{babashka/babashka.pods
{:sha "1245cb26baf6b135abc349b3b25dbd6ca82799bc"
:git/url ""}}}
and build.clj
(ns site.build
(:require [babashka.pods :as pods]))
I get the error:
clojure.lang.ExceptionInfo: Could not resolve symbol: cheshire/parse-string-strict [at /home/tom/.gitlibs/libs/babashka/babashka.pods/1245cb26baf6b135abc349b3b25dbd6ca82799bc/src/babashka/pods/impl.clj, line 90, column 33]
@tomisme You don't run babashka.pods as a library with bb, it's already included in bb itself. However, it's weird that it tries to load it from the library nonetheless. What version of bb are you running?
0.1.3-1... hmm I never released something with that suffic, so that -1 must be coming from a specific package manager I think - but nice that it works now
Oh cool. So if you compile the main class with Clojure yourself, you can still run a babashka uberjar with the JVM:
$ cat src/foo.clj
(ns foo (:gen-class)) (defn -main [& args] (prn :hello))
$ mkdir -p classes && clojure -e "(require 'foo) (compile 'foo)"
foo
$ bb -cp $(clojure -Spath):classes -m foo --uberjar foo.jar
$ java -jar foo.jar
:hello
What would be a reasonable default for printing a stacktrace from bb when you have a fairly large stack? I was thinking the first 5 and last 5 items maybe?
$ lein bb -e "(defn f [_] (/ 1 0)) (require '[spartan.spec :as s]) (s/explain (s/cat :x int? :y f) [1 #{:foo}]) nil"
java.lang.ArithmeticException: Divide by zero [at line 1, column 13]
Stacktrace:
clojure.core// - <built-in>
user - <expr>:1:13
spartan.spec/dt local: pred - /Users/borkdude/.gitlibs/libs/borkdude/spartan.spec/ff7317d67ec15f188afb856d37090e5c9509374e/src/spartan/spec.clj:604:5
spartan.spec/dt - /Users/borkdude/.gitlibs/libs/borkdude/spartan.spec/ff7317d67ec15f188afb856d37090e5c9509374e/src/spartan/spec.clj:611:16
spartan.spec/dt - /Users/borkdude/.gitlibs/libs/borkdude/spartan.spec/ff7317d67ec15f188afb856d37090e5c9509374e/src/spartan/spec.clj:602:8
...
spartan.spec/explain-out - /Users/borkdude/.gitlibs/libs/borkdude/spartan.spec/ff7317d67ec15f188afb856d37090e5c9509374e/src/spartan/spec.clj:279:16
spartan.spec/explain-out - /Users/borkdude/.gitlibs/libs/borkdude/spartan.spec/ff7317d67ec15f188afb856d37090e5c9509374e/src/spartan/spec.clj:269:1
spartan.spec/explain - /Users/borkdude/.gitlibs/libs/borkdude/spartan.spec/ff7317d67ec15f188afb856d37090e5c9509374e/src/spartan/spec.clj:279:3
spartan.spec/explain - /Users/borkdude/.gitlibs/libs/borkdude/spartan.spec/ff7317d67ec15f188afb856d37090e5c9509374e/src/spartan/spec.clj:276:1
user - <expr>:1:54
Think that could work. Would you also be interested in pointing the error with an arrow like in figwheel? I have done this with Sci in another context
would be something like this
Do you already know where you would like to have this or shall I try to get it working first?
There was a request by a clj-kondo hooks users if the [at line ...] part could be made optional. I'm considering making this part of the ex-data instead of the message, so consumers can append it optionally.
I think the place for that would be in babashka.main clj (see branch names posted in channel)
Thanks!
There is a function error-handler or something in which currently the stacktrace is printed
I need access to the lines where it was failing. In my solution here I parse the whole file and index the lines to get to the relevant lines. So a fully qualified path or maybe better the string of the file would work
it works like this
(defn error-lines
[ex code]
(let [data (ex-data ex)
matching-line (dec (get-line data))
start-line (max (- matching-line 4) 0)
end-line (+ matching-line 6)
[before [matching-line & after] :as snippet-lines]
(->>
(clojure.string/split-lines code)
(map-indexed list)
(drop start-line)
(take (- end-line start-line))
(split-at (- matching-line start-line)))]
(concat
(for [[line-number line] before]
[:normal line-number line])
[(into [:error-line] matching-line)
[:error-message nil (str (clojure.string/join (repeat (dec (get-column data)) " "))
(str "^--- " (ex-message ex)))]]
(for [[line-number line] after]
[:normal line-number line]))))
I reverse engineered figwheel 🙂
In sci namespaces.cljc we have source-fn
which contains relevant code to obtain the right file.
Another option would be to forward the file to exception here? https://github.com/borkdude/babashka/blob/issue-508-free-st/src/babashka/main.clj#L586-L588
Not sure about the preloads
ah yeah
The relevant bit in sci is here: https://github.com/borkdude/sci/blob/b6cd6550493a8ecea6dcf472e342861316333aac/src/sci/impl/utils.cljc#L86 Currently on exception, I'm building a stack of expression objects, each have a file, line and column
Ah cool. I’ve build and tested the code with simple scenarios and it took a while before I had it right. Some expections can also not be displayed properly this way. I’ve tested it with a web app and when you have react (reagent) errors this way of reporting is not helpful
So I try to detect these different cases and show a different kind of error
> So we can just pull the file from that and add it to the exception info Sounds like a good idea
btw if you want to go overboard with colors 🙂 I used the flag :normal-line
, :error-line
and :error-message
for formatting (in the browser):
the error line is white and the error message is red.
Maybe a future extension for fancy shells
Yeah that's nice. Maybe for a future version, gotta save some cool things for later ;)
haha good marketing strategy indeed
Did something here https://github.com/borkdude/babashka/pull/545 There is still something missing (second case). I’m guessing file it is not always available
$ lein bb -e "
1
2
x
"
clojure.lang.ExceptionInfo: Could not resolve symbol: x [at <expr>, line 4, column 1]
1:
2: 1
3: 2
4: x
^--- Could not resolve symbol: x [at <expr>, line 4, column 1]
$ lein bb -e "
(defn foo [] (/ 1 0))
(foo)
"
java.lang.ArithmeticException: Divide by zero [at <expr>, line 2, column 14]
1:
2: (defn foo [] (/ 1 0))
^--- Divide by zero [at <expr>, line 2, column 14]
3: (foo)
Stacktrace:
clojure.core// - <built-in>
user/foo - <expr>:2:14
user/foo - <expr>:2:1
user - <expr>:3:1