[#836] Add :error-fn option to shell

This commit is contained in:
Michiel Borkent 2021-05-13 11:45:27 +02:00
parent 5554619a9d
commit 5014012bd6
2 changed files with 25 additions and 5 deletions

View file

@ -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

View file

@ -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}