Skip to content

Commit

Permalink
read-ns-form: rethrow FileNotFoundExceptions more informatively
Browse files Browse the repository at this point in the history
Fixes #142
  • Loading branch information
vemv committed Feb 9, 2022
1 parent 56ac8e2 commit ce28f9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* [#173](https://github.com/clojure-emacs/refactor-nrepl/issues/173): `rename-file-or-dir`: rename more kinds of constructs in dependent namespaces: namespace-qualified maps, fully-qualified functions, metadata.
* [#194](https://github.com/clojure-emacs/refactor-nrepl/issues/194): Don't prune `require` forms if they are needed for a given `import` to work.
* [#142](https://github.com/clojure-emacs/refactor-nrepl/issues/142): `read-ns-form`: report more informatively when a non-existing file is being processed.

## 3.3.1

Expand Down
38 changes: 19 additions & 19 deletions src/refactor_nrepl/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[refactor-nrepl.s-expressions :as sexp]
[refactor-nrepl.util :as util :refer [normalize-to-unix-path]])
(:import
(java.io File FileReader PushbackReader StringReader)))
(java.io File FileNotFoundException FileReader PushbackReader StringReader)))

;; Require our `fs` customizations before `fs` is loaded:
(require '[refactor-nrepl.fs])
Expand Down Expand Up @@ -152,28 +152,28 @@

(defn read-ns-form
([path]
(let [^String path-string (when (string? path)
path)
^File path-file (when-not path-string
path)]
(with-open [file-reader (or (some-> path-string FileReader.)
(some-> path-file FileReader.))]
(try
(parse/read-ns-decl (readers/indexing-push-back-reader
(PushbackReader. file-reader)))
(catch Exception _ nil)))))
(read-ns-form path nil))
([dialect path]
(let [^String path-string (when (string? path)
path)
^File path-file (when-not path-string
path)]
(with-open [file-reader (or (some-> path-string FileReader.)
(some-> path-file FileReader.))]
(try
(parse/read-ns-decl (readers/indexing-push-back-reader
(PushbackReader. file-reader))
{:read-cond :allow :features #{dialect}})
(catch Exception _ nil))))))
path)
^File file (or path-file (File. path-string))]
(try
(with-open [file-reader (FileReader. file)]
(try
(parse/read-ns-decl (readers/indexing-push-back-reader
(PushbackReader. file-reader))
(if dialect
{:read-cond :allow :features #{dialect}}
nil))
(catch Exception _ nil)))
(catch FileNotFoundException e
(throw (ex-info (format "No such file: %s. This typically indicates an invalid request client-side."
(pr-str path))
{:path path
:dialect dialect}
e)))))))

(defn cljc-extension? [^String path]
(.endsWith path ".cljc"))
Expand Down

0 comments on commit ce28f9c

Please sign in to comment.