Fork me on GitHub
#babashka
<
2021-06-18
>
rafaeldelboni12:06:59

Hey Borkdude I just rewrote my https://github.com/rafaeldelboni/dotfiles/tree/master/config/i3blocks/scripts using babashka instead of bash and is incredible, thanks a lot for all your work and enabling us to move out the ugly bashscripts 😄

borkdude12:06:46

🎉 thanks for sharing :)

littleli13:06:20

damn, this is cool 🙂

borkdude13:06:48

Btw, feel free to post it here: https://github.com/babashka/babashka/discussions/categories/show-and-tell I think the Github Discussions board can be a nice place to share this stuff as well.

rafaeldelboni13:06:11

Ah ok I will, thanks

dabrazhe17:06:51

I'm a getting a stack trace as the result of a function chain, but no idea in where / which function it has occurred. Is there a way to improve it ?

#error {
 :cause nil
 :via
 [{:type java.lang.NullPointerException
   :message nil
   :at [clojure.lang.Numbers ops Numbers.java 1068]}]
 :trace
 [[clojure.lang.Numbers ops Numbers.java 1068]
  [clojure.lang.Numbers isZero Numbers.java 117]
  [clojure.core$zero_QMARK_ invokeStatic core.clj 874]
  [clojure.core$zero_QMARK_ invoke core.clj 869]
  [sci.impl.analyzer$return_call$fn__18447 invoke analyzer.cljc 811]  etc...

borkdude17:06:41

@dennisa when you invoke the script from the command line you will likely get a better error message

borkdude17:06:54

also the exception should probably have a line and column number

borkdude17:06:57

and file name

dabrazhe17:06:11

in CLI, but not in the Repl?

borkdude17:06:13

if not, repro welcome

borkdude17:06:35

are you using the nREPL btw? please provide as much info as you can about your environment

dabrazhe17:06:37

#error {
 :cause nil
 :via
 [{:type java.lang.NullPointerException
   :message nil
   :at [clojure.lang.Numbers ops Numbers.java 1068]}]
 :trace
 [[clojure.lang.Numbers ops Numbers.java 1068]
  [clojure.lang.Numbers isZero Numbers.java 117]
  [clojure.core$zero_QMARK_ invokeStatic core.clj 874]
  [clojure.core$zero_QMARK_ invoke core.clj 869]
  [sci.impl.analyzer$return_call$fn__18447 invoke analyzer.cljc 811]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.analyzer$return_if$fn__18211 invoke analyzer.cljc 462]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.evaluator$eval_let$fn__17163 invoke evaluator.cljc 68]
  [sci.impl.evaluator$eval_let invokeStatic evaluator.cljc 62]
  [sci.impl.analyzer$expand_let_STAR_$fn__18173 invoke analyzer.cljc 338]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.evaluator$eval_try invokeStatic evaluat
or.cljc 133]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 403]
  [sci.impl.analyzer$return_do$fn__17612 invoke analyzer.cljc 117]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.fns$fun$arity_4__16544 invoke fns.cljc 149]
  [sci.impl.vars.SciVar invoke vars.cljc 321]
  [sci.impl.analyzer$return_call$fn__18453 invoke analyzer.cljc 811]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.evaluator$eval_let$fn__17163 invoke evaluator.cljc 68]
  [sci.impl.evaluator$eval_let invokeStatic evaluator.cljc 62]
  [sci.impl.analyzer$expand_let_STAR_$fn__18173 invoke analyzer.cljc 338]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.fns$fun$arity_2__16520 invoke fns.cljc 141]
  [sci.impl.vars.SciVar invoke vars.cljc 317]
  [sci.impl.analyzer$return_call$fn__18449 invoke analyzer.cljc 8
11]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.interpreter$eval_form invokeStatic interpreter.cljc 77]
  [sci.core$eval_form invokeStatic core.cljc 257]
  [babashka.nrepl.impl.server$eval_msg$fn__30614 invoke server.clj 44]
  [babashka.nrepl.impl.server$eval_msg invokeStatic server.clj 32]
  [babashka.nrepl.impl.server$session_loop invokeStatic server.clj 223]
  [babashka.nrepl.impl.server$listen$fn__30688 invoke server.clj 264]
  [sci.impl.vars$binding_conveyor_fn$fn__8727 invoke vars.cljc 147]
  [clojure.core$binding_conveyor_fn$fn__5773 invoke core.clj 2034]
  [clojure.lang.AFn call AFn.java 18]
  [java.util.concurrent.FutureTask run FutureTask.java 264]
  [java.util.concurrent.ThreadPoolExecutor runWorker ThreadPoolExecutor.java 1128]
  [java.util.concurrent.ThreadPoolExecutor$Worker run ThreadPoolExecutor.java 628]
  [java.lang.Thread run Thread.java 834]
  [com.oracle.svm.core.thread.JavaThreads threadStartRoutine JavaThreads.java 519]
  [com.oracle.svm.core.posix.thread.Pos
ixJavaThreads pthreadStartRoutine PosixJavaThreads.java 192]]}

dabrazhe17:06:16

yes, nrepl connected from Calva in VSC on the mac; the trace in thread above

borkdude17:06:00

so the issue is likely that you are calling zero? on a nil value

borkdude17:06:09

but you probably already guessed this

borkdude17:06:24

when invoking the script from the command line you will get a proper stack trace from bb itself

borkdude17:06:34

but the nrepl environment doesn't have this yet, I think

dabrazhe17:06:35

Yes, searching in the editor for zero? :))

borkdude17:06:29

when I evaluate:

(defn foo []
  (zero? nil))

(foo)
I see
clojure.lang.ExceptionInfo: null
{:type :sci/error, :line 4, :column 3, :message nil, :sci.impl/callstack #object[clojure.lang.Delay 0x4e72f87f {:status :pending, :val nil}], :file "\n\n(defn foo []\n  (zero? nil))\n", :locals {}}
as the first lines

borkdude17:06:41

and this gives you some clue where to look, usually

borkdude17:06:24

but with the command line get:

$ bb /tmp/foo.clj
----- Error --------------------------------------------------------------------
Type:     java.lang.NullPointerException
Location: /tmp/foo.clj:4:3

----- Context ------------------------------------------------------------------
1:
2:
3: (defn foo []
4:   (zero? nil))
     ^---
5:
6: (foo)

----- Stack trace --------------------------------------------------------------
clojure.core/zero? - <built-in>
user/foo           - /tmp/foo.clj:4:3
user/foo           - /tmp/foo.clj:3:1
user               - /tmp/foo.clj:6:1

borkdude17:06:29

which is much better

dabrazhe17:06:00

is there a way I can impove it on my end in repl? : )

borkdude17:06:32

I don't think so, at the moment

Jakub Šťastný22:06:36

Is there some Babashka-compatible templating engine for Clojure? When I say templating engine, I mean for instance ERB in Ruby (`<%= eval_expr(whatevs) %>`) or <?php in PHP. What I'm trying to do: I have a README template which is inherits a lot of data from the monorepo's README, but needs substituting some project-specific stuff.

borkdude22:06:22

@jakub.stastny.pt_serv babashka has Selmer built-in :)