Tasks: don't print context on shell error
This commit is contained in:
parent
b779f45407
commit
bf6f19dc97
2 changed files with 48 additions and 45 deletions
|
|
@ -79,8 +79,8 @@
|
||||||
(defn error-handler [^Exception e opts]
|
(defn error-handler [^Exception e opts]
|
||||||
(binding [*out* *err*]
|
(binding [*out* *err*]
|
||||||
(let [d (ex-data e)
|
(let [d (ex-data e)
|
||||||
cause-exit (some-> e ex-cause ex-data :exit)
|
cause-exit (some-> e ex-cause ex-data :babashka/exit)
|
||||||
exit-code (or (:exit d) cause-exit)
|
exit-code (or (:babashka/exit d) cause-exit)
|
||||||
sci-error? (isa? (:type d) :sci/error)
|
sci-error? (isa? (:type d) :sci/error)
|
||||||
ex-name (when sci-error?
|
ex-name (when sci-error?
|
||||||
(some-> ^Throwable (ex-cause e)
|
(some-> ^Throwable (ex-cause e)
|
||||||
|
|
@ -88,41 +88,45 @@
|
||||||
stacktrace (some->
|
stacktrace (some->
|
||||||
d :sci.impl/callstack
|
d :sci.impl/callstack
|
||||||
cs/stacktrace)]
|
cs/stacktrace)]
|
||||||
(if exit-code [nil exit-code]
|
(if exit-code
|
||||||
(do
|
(do
|
||||||
(ruler "Error")
|
(when-let [m (.getMessage e)]
|
||||||
(println "Type: " (or
|
(println m))
|
||||||
ex-name
|
[nil exit-code])
|
||||||
(.. e getClass getName)))
|
(do
|
||||||
(when-let [m (.getMessage e)]
|
(ruler "Error")
|
||||||
(println (str "Message: " m)))
|
(println "Type: " (or
|
||||||
(let [{:keys [:file :line :column]} d]
|
ex-name
|
||||||
(when line
|
(.. e getClass getName)))
|
||||||
(println (str "Location: "
|
(when-let [m (.getMessage e)]
|
||||||
(when file (str file ":"))
|
(println (str "Message: " m)))
|
||||||
line ":" column""))))
|
(let [{:keys [:file :line :column]} d]
|
||||||
(when-let [phase (cs/phase e stacktrace)]
|
(when line
|
||||||
(println "Phase: " phase))
|
(println (str "Location: "
|
||||||
(println)
|
(when file (str file ":"))
|
||||||
(when-let [ec (when sci-error?
|
line ":" column""))))
|
||||||
(error-context e opts))]
|
(when-let [phase (cs/phase e stacktrace)]
|
||||||
(ruler "Context")
|
(println "Phase: " phase))
|
||||||
(println ec)
|
(println)
|
||||||
(println))
|
(when-let [ec (when sci-error?
|
||||||
(when-let [locals (not-empty (:locals d))]
|
(error-context e opts))]
|
||||||
(ruler "Locals")
|
(ruler "Context")
|
||||||
(print-locals locals)
|
(println ec)
|
||||||
(println))
|
(println))
|
||||||
(when sci-error?
|
(when-let [locals (not-empty (:locals d))]
|
||||||
(when-let
|
(ruler "Locals")
|
||||||
[st (let [st (with-out-str
|
(print-locals locals)
|
||||||
(when stacktrace
|
(println))
|
||||||
(print-stacktrace stacktrace opts)))]
|
(when sci-error?
|
||||||
(when-not (str/blank? st) st))]
|
(when-let
|
||||||
(ruler "Stack trace")
|
[st (let [st (with-out-str
|
||||||
(println st)))
|
(when stacktrace
|
||||||
(when (:debug opts)
|
(print-stacktrace stacktrace opts)))]
|
||||||
(ruler "Exception")
|
(when-not (str/blank? st) st))]
|
||||||
(print-stack-trace e))
|
(ruler "Stack trace")
|
||||||
(flush)
|
(println st)))
|
||||||
[nil 1])))))
|
(when (:debug opts)
|
||||||
|
(ruler "Exception")
|
||||||
|
(print-stack-trace e))
|
||||||
|
(flush)
|
||||||
|
[nil 1])))))
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,10 @@
|
||||||
(continue proc))
|
(continue proc))
|
||||||
zero-exit?)]
|
zero-exit?)]
|
||||||
(if continue? proc
|
(if continue? proc
|
||||||
(do (when-not zero-exit?
|
(throw (ex-info (str "Error while executing task: " (:name @task))
|
||||||
(binding [*out* *err*]
|
{:proc proc
|
||||||
(println "Received non-zero exit code in task:" (:name @task))))
|
:task task
|
||||||
(throw (ex-info (str "Error during task: " (:name @task))
|
:babashka/exit exit-code})))))))
|
||||||
{:proc proc :task task :exit exit-code}))))))))
|
|
||||||
|
|
||||||
(def default-opts
|
(def default-opts
|
||||||
{:in :inherit
|
{:in :inherit
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue