diff --git a/process b/process index 7847bdd5..cc298e4a 160000 --- a/process +++ b/process @@ -1 +1 @@ -Subproject commit 7847bdd56bb8db3293070a5c09b94dddc77c0155 +Subproject commit cc298e4a75e307f1265dcce11c629ea088423a9e diff --git a/src/babashka/impl/error_handler.clj b/src/babashka/impl/error_handler.clj index 80c9b0ef..f741c6b3 100644 --- a/src/babashka/impl/error_handler.clj +++ b/src/babashka/impl/error_handler.clj @@ -18,18 +18,18 @@ (drop (- stack-count 5) stacktrace)])))) (defn print-stacktrace - [stacktrace {:keys [:verbose?]}] + [stacktrace {:keys [:debug]}] (let [stacktrace (sci/format-stacktrace stacktrace) - segments (split-stacktrace stacktrace verbose?) + segments (split-stacktrace stacktrace debug) [fst snd] segments] (run! println fst) (when snd - (println "...") + (println "... (run with --debug to see elided elements)") (run! println snd)))) (defn error-context [ex opts] (let [{:keys [:file :line :column]} (ex-data ex)] - (when (and file line) + (when (and file line column) (when-let [content (case file "" (:expression opts) "" (:preloads opts) @@ -81,6 +81,21 @@ (when (some :macro stacktrace) "macroexpand"))) +(defn render-native-sym [sym] + (let [sym (-> (str sym) + (clojure.lang.Compiler/demunge) + symbol) + ns (namespace sym)] + (when ns + (let [ns (symbol ns) + nm (symbol (name sym))] + {:ns ns + :name nm + :sci/built-in true})))) + +(defn render-native-stacktrace-elem [[sym _ _file _line]] + (render-native-sym sym)) + (defn error-handler [^Exception e opts] (binding [*out* *err*] (let [d (ex-data e) @@ -90,7 +105,12 @@ ex-name (when sci-error? (some-> ^Throwable (ex-cause e) .getClass .getName)) - stacktrace (sci/stacktrace e)] + stacktrace (dedupe + (concat (sequence (comp (map StackTraceElement->vec) + (take-while #(not (str/starts-with? (first %) "sci.impl."))) + (map render-native-stacktrace-elem)) + (.getStackTrace (or (ex-cause e) e))) + (sci/stacktrace e)))] (if exit-code (do (when-let [m (.getMessage e)] diff --git a/test/babashka/error_test.clj b/test/babashka/error_test.clj index 70682330..d79d0ba9 100644 --- a/test/babashka/error_test.clj +++ b/test/babashka/error_test.clj @@ -248,3 +248,10 @@ user - :1:45 ----- Exception ---------------------------------------------------------------- clojure.lang.ExceptionInfo: null {:type :sci/error, :line 1, :column 19,"))))) + +(deftest native-stacktrace-test + (let [output (try (tu/bb nil "(merge 1 2 3)") + (is false) + (catch Exception e (ex-message e)))] + (is (str/includes? (tu/normalize output) + "clojure.core/reduce1 - "))))