babashka

Jan Šuráň 2026-04-28T21:08:07.952479Z

Suspicious error reporting I have the following babashka code:

(defn run-failing-tests []
  (println "Running failing tests...")
  (let [error-files (fs/list-dir error-files-directory)
        failing-files (filter (fn [error-file error-files]
                                (let [form (slurp (str error-file))
                                      {clojure-out :out clojure-err :err} (run-clojure form)
                                      {tinyclj-out :out tinyclj-err :err} (run-tinyclj form)]
                                  (or (str/blank? clojure-err)
                                      (str/blank? tinyclj-err))))
                              error-files)]
    (if (empty? failing-files)
      (println "All error files failed as expected!")
      (do (println "The following error files did not fail as expected:")
          (doseq [failing-file failing-files]
            (println " - " failing-file))
          (System/exit 1)))))
Attached you can find the error message. So it basically says the error comes from the empty? call - but it does not. The root cause is that the filter function takes 2 arguments. The lazy sequence might actually be evaluated in the empty? call, but the error message doesn't really help there.

borkdude 2026-04-28T21:10:54.199309Z

maybe you can make a smaller repro that doesn't depend on anything externally and then post here? I'll try to run it

Jan Šuráň 2026-04-28T21:13:03.579249Z

Sure!

Jan Šuráň 2026-04-28T21:15:59.424939Z

(let [res (filter (fn [a b]
                    (even? a))
                  (range 10))]
  (empty? res))
clojure.lang.ArityException: Wrong number of args (1) passed to: function of arity 2 [at <repl>:4:10]

Jan Šuráň 2026-04-28T21:18:21.148079Z

I don't know, Clojure has similar reporting 😕 the exception is thrown later when realizing the seq... Not sure if there's some way to improve this... Lazy sequences can be evil 😄

borkdude 2026-04-28T21:18:58.111809Z

Clojure also reports line 4 I was going to say :)

borkdude 2026-04-28T21:19:25.688659Z

The error happens there because that's where the lazy seq is realized

Jan Šuráň 2026-04-28T21:20:56.352929Z

user=> (empty? [] []) clojure.lang.ArityException: Wrong number of args (2) passed to: clojure.core/empty? [at :5:1] When the function is named, everything works fine... I was confused because it didn't mention the function empty? specifically... which makes sense because the function where the error originated is actually anonymous

borkdude 2026-04-28T21:21:38.313589Z

yeah, laziness obscures this I agree