From 46b2f69fa5acd5fbdd89e285706dc574737a47f3 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sat, 15 Jul 2023 16:50:01 +0200 Subject: [PATCH] [fix] Prevent `get-source` from throwing for JAR resources --- src/taoensso/truss/impl.cljc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/taoensso/truss/impl.cljc b/src/taoensso/truss/impl.cljc index d1a031f..73cf557 100644 --- a/src/taoensso/truss/impl.cljc +++ b/src/taoensso/truss/impl.cljc @@ -56,24 +56,23 @@ (defn get-source [form env] (let [{:keys [line column file]} (meta form) file - (if (:ns env) - - ;; Compiling cljs - ;; Note that meta (and thus file) can be nil due to CLJ-865 - (if-let [classpath-file (and file (io/resource file))] - (.getPath (io/file classpath-file)) - file) - - ;; Compiling clj - (when-let [f *file*] - (let [f (str f)] - (when-not (contains? #{"NO_SOURCE_PATH" "NO_SOURCE_FILE"} f) - f))))] + (if-not (:ns env) + *file* ; Compiling clj + (or ; Compiling cljs + (when-let [url (and file (try (io/resource file) (catch Throwable _ nil)))] + (try (.getPath (io/file url)) (catch Throwable _ nil)) + (do (str url))) + file))] {:ns (str *ns*) :line line :column column - :file file}))) + :file + (when (string? file) + (when-not (contains? #{"NO_SOURCE_PATH" "NO_SOURCE_FILE" ""} file) + file))}))) + +(comment (io/resource "taoensso/truss.cljc")) ;;;; Truss