Skip to content

Commit

Permalink
Catch exceptions while performing get-ns-info-from-file-with-caching
Browse files Browse the repository at this point in the history
Fixes #373
  • Loading branch information
vemv committed Mar 14, 2022
1 parent 591d716 commit 9eff1a3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
```

Expand Down Expand Up @@ -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
```

Expand Down
8 changes: 6 additions & 2 deletions src/refactor_nrepl/ns/libspecs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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))

Expand Down
3 changes: 2 additions & 1 deletion test/refactor_nrepl/ns/libspecs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))

Expand Down
4 changes: 2 additions & 2 deletions test/refactor_nrepl/ns/namespace_aliases_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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")))

0 comments on commit 9eff1a3

Please sign in to comment.