From 9eff1a3e844300d48344bdc8f6a60f1646aeb585 Mon Sep 17 00:00:00 2001 From: vemv Date: Mon, 14 Mar 2022 23:14:25 +0100 Subject: [PATCH] Catch exceptions while performing `get-ns-info-from-file-with-caching` Fixes https://github.com/clojure-emacs/refactor-nrepl/issues/373 --- CHANGELOG.md | 4 ++++ README.md | 6 +++--- src/refactor_nrepl/ns/libspecs.clj | 8 ++++++-- test/refactor_nrepl/ns/libspecs_test.clj | 3 ++- test/refactor_nrepl/ns/namespace_aliases_test.clj | 4 ++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97a6644e..4c32221d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## 3.4.2 + +* [#373](https://github.com/clojure-emacs/refactor-nrepl/issues/373): catch exceptions while performing `get-ns-info-from-file-with-caching`. + ## 3.4.1 * Offer `refactor-nrepl.ns.libspecs/namespace-aliases-for` function. diff --git a/README.md b/README.md index 1fd855ad..7006e603 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Be aware that this isn't the case if you connect to an already running REPL proc Add the following, either in your project's `project.clj`, or in the `:user` profile found at `~/.lein/profiles.clj`: ```clojure -:plugins [[refactor-nrepl "3.4.1"] +:plugins [[refactor-nrepl "3.4.2"] [cider/cider-nrepl "0.28.3"]] ``` @@ -360,12 +360,12 @@ If you want to use `mranderson` while developing locally with the REPL, the sour When you want to release locally to the following: - PROJECT_VERSION=3.4.1 make install + PROJECT_VERSION=3.4.2 make install And here's how to deploy to Clojars: ```bash -git tag -a v3.4.1 -m "3.4.1" +git tag -a v3.4.2 -m "3.4.2" git push --tags ``` diff --git a/src/refactor_nrepl/ns/libspecs.clj b/src/refactor_nrepl/ns/libspecs.clj index 9fd78495..a2333fa8 100644 --- a/src/refactor_nrepl/ns/libspecs.clj +++ b/src/refactor_nrepl/ns/libspecs.clj @@ -56,7 +56,11 @@ (defn- get-ns-info-from-file-with-caching [lang f] (if-let [v (get-cached-ns-info f lang)] v - (put-cached-ns-info! f lang))) + (try + (put-cached-ns-info! f lang) + (catch Exception e + ;; put-cached-ns-info! can throw arbitrary exceptions, which should not abort underlying ops: + (util/maybe-log-exception e))))) (defn- get-libspec-from-file-with-caching [lang f] (:libspecs (get-ns-info-from-file-with-caching lang f))) @@ -143,7 +147,7 @@ include-tentative-aliases? (update :cljs add-tentative-aliases :cljs files ignore-errors?))))) (defn namespace-aliases-response [{:keys [suggest]}] - (namespace-aliases false + (namespace-aliases true (core/source-dirs-on-classpath) suggest)) diff --git a/test/refactor_nrepl/ns/libspecs_test.clj b/test/refactor_nrepl/ns/libspecs_test.clj index 09da76d3..2474193a 100644 --- a/test/refactor_nrepl/ns/libspecs_test.clj +++ b/test/refactor_nrepl/ns/libspecs_test.clj @@ -19,7 +19,8 @@ (testing "`ignore-errors?`" (let [files [unreadable-file]] - (is (thrown? Exception (sut/add-tentative-aliases {} :clj files false))) + (is (any? (sut/add-tentative-aliases {} :clj files false)) + "No exceptions are thrown for a problematic file") (is (= {} (sut/add-tentative-aliases {} :clj files true))))) diff --git a/test/refactor_nrepl/ns/namespace_aliases_test.clj b/test/refactor_nrepl/ns/namespace_aliases_test.clj index 740c1c0b..4eb2895f 100644 --- a/test/refactor_nrepl/ns/namespace_aliases_test.clj +++ b/test/refactor_nrepl/ns/namespace_aliases_test.clj @@ -39,5 +39,5 @@ (reset! @#'sut/cache {}) (with-redefs [refactor-nrepl.ns.libspecs/put-cached-ns-info! (fn [& _] (throw (Exception. "Expected!")))] - (is (thrown-with-msg? Exception #"Expected!" - (sut/namespace-aliases false))))) + (is (any? (sut/namespace-aliases false)) + "No exceptions are rethrown")))