#1410: better error message when exec fn doesn't exist

This commit is contained in:
Michiel Borkent 2024-01-09 15:11:42 +01:00
parent 2166c42de2
commit b337e032b6
2 changed files with 4 additions and 0 deletions

View file

@ -17,6 +17,8 @@
(let [extra-opts '%s
sym `%s
the-var (requiring-resolve sym)
_ (when-not the-var
(throw (ex-info (str \"Could not resolve sym to a function: \" sym) {:babashka/exit 1})))
the-var-meta (meta the-var)
ns (:ns (meta the-var))
ns-meta (meta ns)

View file

@ -11,6 +11,8 @@
(deftest exec-test
(is (= {:foo 1} (edn/read-string (bb "-x" "prn" "--foo" "1"))))
(is (thrown? Exception (bb "-x" "json/generate-string" "--foo" "1")))
(is (thrown-with-msg? Exception #"Could not resolve sym to a function: clojure.core/generate-string"
(bb "-x" "clojure.core/generate-string" "--foo" "1")))
(is (= {:foo 1} (cheshire/parse-string
(edn/read-string
(bb "--prn" "-x" "cheshire.core/generate-string" "--foo" "1")) true))))