Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## master (unreleased)
* [#158](https://github.com/clojure-emacs/orchard/issues/158): Make classpath-namespaces resilient to faulty ns declarations.

## 0.9.2 (2022-02-22)

Expand Down
3 changes: 2 additions & 1 deletion src/orchard/namespace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
(cond
(#{::eof ::fail} found) nil
(and (list? found)
(-> found first #{`ns 'ns}))
(-> found first #{`ns 'ns})
(symbol? (second found)))
(second found)
:else (recur))))))

Expand Down
3 changes: 3 additions & 0 deletions test/orchard/namespace_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
(testing "when multiple ns forms are present"
(spit url "(ns ns1) (ns ns2) (ns ns3)")
(is (= 'ns1 (sut/read-namespace uri))))
(testing "when ns form is invalid"
(spit url "(ns (:require [clojure.string]))")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ns foo (:requires [clojure.string])) is a also a good example to be covered.

Accordingly, probably a try/catch would be better than the proposed approach - there can be few reasons why a ns parsing could fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error I've reported in #158 does not occur here, but it originates here, see:

(pmap jvm-clojure-resource-name->ns-name)
(filter identity)
(sort)))

What happens without my change is that we try to sort and hence compare a seq like (:requires [clojure.string]) with symbols and that fails.

I do think a try/catch could be good & helpful in addition to that, but then I'd place it way further up the stack, possibly in cider-nrepl in analyze-stacktrace https://github.com/clojure-emacs/cider-nrepl/blob/5c0f21197fcccb1b2ca67054cab1dcc8a6af2c7f/src/cider/nrepl/middleware/stacktrace.clj#L216

Btw, re-reading the issue I'm noticing now I should have pointed out the stacktrace in https://gist.github.com/mk/bd82092048d733ef3de0e312898f47b4 more promintely.

(is (nil? (sut/read-namespace uri))))
(testing "of top-level forms only"
(spit url "(comment (ns ns1)) (ns ns2) (ns ns3)")
(is (= 'ns2 (sut/read-namespace uri))))
Expand Down