From b337e032b62515366fbc8b360fec3f6fa373e8b4 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 9 Jan 2024 15:11:42 +0100 Subject: [PATCH] #1410: better error message when exec fn doesn't exist --- src/babashka/impl/cli.clj | 2 ++ test/babashka/exec_test.clj | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/babashka/impl/cli.clj b/src/babashka/impl/cli.clj index 7a152fc2..1ec08daf 100644 --- a/src/babashka/impl/cli.clj +++ b/src/babashka/impl/cli.clj @@ -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) diff --git a/test/babashka/exec_test.clj b/test/babashka/exec_test.clj index 960de5fa..69d13659 100644 --- a/test/babashka/exec_test.clj +++ b/test/babashka/exec_test.clj @@ -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))))