[#836] Add :error-fn option to shell
This commit is contained in:
parent
5554619a9d
commit
5014012bd6
2 changed files with 25 additions and 5 deletions
|
|
@ -44,12 +44,15 @@
|
||||||
continue? (if continue
|
continue? (if continue
|
||||||
(or (true? continue)
|
(or (true? continue)
|
||||||
(continue proc))
|
(continue proc))
|
||||||
zero-exit?)]
|
zero-exit?)
|
||||||
|
info {:proc proc
|
||||||
|
:task task
|
||||||
|
:babashka/exit exit-code}]
|
||||||
(if continue? proc
|
(if continue? proc
|
||||||
(throw (ex-info (str "Error while executing task: " (:name @task))
|
(if-let [err-fn (:error-fn opts)]
|
||||||
{:proc proc
|
(err-fn info)
|
||||||
:task task
|
(throw (ex-info (str "Error while executing task: " (:name @task))
|
||||||
:babashka/exit exit-code})))))))
|
info))))))))
|
||||||
|
|
||||||
(def default-opts
|
(def default-opts
|
||||||
{:in :inherit
|
{:in :inherit
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,23 @@
|
||||||
"ls foobar")
|
"ls foobar")
|
||||||
:exit)}}
|
:exit)}}
|
||||||
(is (pos? (bb "run" "--prn" "foo")))))
|
(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)
|
(fs/delete out)
|
||||||
(testing "clojure test"
|
(testing "clojure test"
|
||||||
(test-utils/with-config {:tasks {'foo (list 'clojure {:out out}
|
(test-utils/with-config {:tasks {'foo (list 'clojure {:out out}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue