diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index d00be0e3..537b8499 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -44,12 +44,15 @@ continue? (if continue (or (true? continue) (continue proc)) - zero-exit?)] + zero-exit?) + info {:proc proc + :task task + :babashka/exit exit-code}] (if continue? proc - (throw (ex-info (str "Error while executing task: " (:name @task)) - {:proc proc - :task task - :babashka/exit exit-code}))))))) + (if-let [err-fn (:error-fn opts)] + (err-fn info) + (throw (ex-info (str "Error while executing task: " (:name @task)) + info)))))))) (def default-opts {:in :inherit diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 516add63..9e6781cb 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -62,6 +62,23 @@ "ls foobar") :exit)}} (is (pos? (bb "run" "--prn" "foo"))))) + (testing "shell test with :error" + (test-utils/with-config + {:tasks {'foo (list '-> (list 'shell {:out out + :err out + :error-fn '(constantly 1337) } + "ls foobar"))}} + (is (= 1337 (bb "run" "--prn" "foo")))) + (test-utils/with-config + {:tasks {'foo (list '-> (list 'shell {:out out + :err out + :error-fn + '(fn [opts] + (and (:task opts) + (:proc opts) + (not (zero? (:exit (:proc opts))))))} + "ls foobar"))}} + (is (true? (bb "run" "--prn" "foo"))))) (fs/delete out) (testing "clojure test" (test-utils/with-config {:tasks {'foo (list 'clojure {:out out}