-
-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve stack trace when errors occur #1322
Comments
Thanks! |
As promised on Slack a few days ago, my related experience. My bb tasks typically delegate to bb scripts with Minimal reproEmpty dir with:
{:paths ["."]
:tasks {atask {:task some-script/-main
:doc "testing 123"}}}
(ns some-script)
(defn -main[& _args]
(println "something bad is about to happen")
(/ 1 0))
(when (= *file* (System/getProperty "babashka.file"))
(apply -main *command-line-args*))
❯ bb --version
babashka v0.9.161 Invoke Task❯ bb atask
something bad is about to happen
----- Error --------------------------------------------------------------------
Type: java.lang.ArithmeticException
Message: Divide by zero Observation: succinct error, maybe I need to use --debug to pinpoint. Invoke Task with --debug❯ bb --debug atask
;; deps
(ns user-b3a54edc-6b16-4f7a-b338-cf37d7a57095 )
(require '[babashka.tasks #_#_:refer [log]])
(when-not (resolve 'clojure)
;; we don't use refer so users can override this
(intern *ns* 'clojure babashka.tasks/clojure))
(when-not (resolve 'shell)
(intern *ns* 'shell babashka.tasks/shell))
(when-not (resolve 'current-task)
(intern *ns* 'current-task babashka.tasks/current-task))
(when-not (resolve 'run)
(intern *ns* 'run babashka.tasks/run))
(when-not (resolve 'exec)
(intern *ns* 'exec @(var babashka.tasks/exec)))
nil
(when-not (resolve 'some-script/-main) (require (quote some-script)))
(def atask (binding [
babashka.tasks/*task* '{:name atask, :task some-script/-main, :doc "testing 123"}]
nil
(apply some-script/-main *command-line-args*))) atask
something bad is about to happen
----- Error --------------------------------------------------------------------
Type: java.lang.ArithmeticException
Message: Divide by zero
----- Exception ----------------------------------------------------------------
java.lang.ArithmeticException: Divide by zero
at clojure.lang.Numbers.divide (Numbers.java:190)
clojure.core$_SLASH_.invokeStatic (core.clj:1029)
clojure.core$_SLASH_.invoke (core.clj:1022)
sci.impl.analyzer$return_call$reify__5211.eval (analyzer.cljc:1205)
sci.impl.analyzer$return_do$reify__4236.eval (analyzer.cljc:139)
sci.impl.fns$fun$arity_0__3012.doInvoke (fns.cljc:83)
clojure.lang.RestFn.invoke (RestFn.java:397)
clojure.lang.AFn.applyToHelper (AFn.java:152)
clojure.lang.RestFn.applyTo (RestFn.java:132)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$apply.invoke (core.clj:662)
sci.lang.Var.invoke (lang.cljc:178)
sci.impl.analyzer$return_call$reify__5211.eval (analyzer.cljc:1205)
sci.impl.analyzer$return_do$reify__4236.eval (analyzer.cljc:139)
sci.impl.evaluator$eval_try.invokeStatic (evaluator.cljc:123)
sci.impl.analyzer$analyze_try$reify__4959.eval (analyzer.cljc:774)
sci.impl.analyzer$return_do$reify__4236.eval (analyzer.cljc:139)
sci.impl.evaluator$eval_let.invokeStatic (evaluator.cljc:71)
sci.impl.analyzer$analyze_let_STAR_$reify__4874.eval (analyzer.cljc:507)
sci.impl.evaluator$eval_def.invokeStatic (evaluator.cljc:75)
sci.impl.analyzer$analyze_def$reify__4891.eval (analyzer.cljc:573)
sci.impl.interpreter$eval_form.invokeStatic (interpreter.cljc:39)
sci.impl.interpreter$eval_string_STAR_.invokeStatic (interpreter.cljc:61)
sci.core$eval_string_STAR_.invokeStatic (core.cljc:261)
babashka.main$exec$fn__31015$fn__31016.invoke (main.clj:955)
babashka.main$exec$fn__31015.invoke (main.clj:955)
babashka.main$exec.invokeStatic (main.clj:945)
babashka.main$main.invokeStatic (main.clj:1052)
babashka.main$main.doInvoke (main.clj:1027)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:667)
babashka.main$_main.invokeStatic (main.clj:1085)
babashka.main$_main.doInvoke (main.clj:1077)
clojure.lang.RestFn.applyTo (RestFn.java:137)
babashka.main.main (:-1) Observation: Stacktrace does not really help me find what threw. Invoke Scriptbb some_script.clj
something bad is about to happen
----- Error --------------------------------------------------------------------
Type: java.lang.ArithmeticException
Message: Divide by zero
Location: /Users/lee/proj/oss/-verify/bb-ex/some_script.clj:5:3
----- Context ------------------------------------------------------------------
1: (ns some-script)
2:
3: (defn -main[& _args]
4: (println "something bad is about to happen")
5: (/ 1 0))
^--- Divide by zero
6:
7: (when (= *file* (System/getProperty "babashka.file"))
8: (apply -main *command-line-args*))
----- Stack trace --------------------------------------------------------------
clojure.core// - <built-in>
some-script - /Users/lee/proj/oss/-verify/bb-ex/some_script.clj:5:3
clojure.core/apply - <built-in>
some-script - /Users/lee/proj/oss/-verify/bb-ex/some_script.clj:8:3 Observation: Ok, good stuff I can pinpoint what threw. Invoke Script with --debugLet's see if --debug gives us more:
Observation: There might be more info there, but maybe not especially helpful in pinpointing what threw. Probably more helpful in debugging sci than what went wrong for me (which is what --debug is likely mainly for anyway). |
New output:
|
Noice! |
I cheered to soon, some tests fail with this fix... |
All good now |
How to reproduce,
In a simple define a bb task as
Run from the command line, the output is:

The text was updated successfully, but these errors were encountered: