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.maybe you can make a smaller repro that doesn't depend on anything externally and then post here? I'll try to run it
Sure!
(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]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 😄
Clojure also reports line 4 I was going to say :)
The error happens there because that's where the lazy seq is realized
user=> (empty? [] [])
clojure.lang.ArityException: Wrong number of args (2) passed to: clojure.core/empty? [at
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
yeah, laziness obscures this I agree