Skip to content

Commit

Permalink
Merge pull request #49 from marick/master
Browse files Browse the repository at this point in the history
Clearer failure when trying to import nonexistent var
  • Loading branch information
ztellman committed Aug 1, 2016
2 parents 8f39702 + 729f3bc commit b56a840
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/potemkin/namespaces.clj
Expand Up @@ -96,6 +96,7 @@
(let [vr (resolve sym)
m (meta vr)]
(cond
(nil? vr) `(throw (ex-info (format "`%s` does not exist" '~sym) {}))
(:macro m) `(import-macro ~sym)
(:arglists m) `(import-fn ~sym)
:else `(import-def ~sym))))
Expand Down
8 changes: 8 additions & 0 deletions test/potemkin/namespaces_test.clj
Expand Up @@ -16,6 +16,7 @@
(import-fn i/inlined-fn)
(import-def i/some-value)


(defn drop-lines [n s]
(->> s str/split-lines (drop n) (interpose "\n") (apply str)))

Expand Down Expand Up @@ -44,3 +45,10 @@
(is (= 1 some-value))
(require 'potemkin.imports-test :reload)
(is (= 1 some-value)))

(deftest import-vars-throws-if-missing-var
(try
(import-vars [clojure.set union onion-misspelled])
(is false "`import-vars` should have thrown an exception")
(catch Exception ex
(is "`clojure.set/onion-misspelled` does not exist" (.getMessage ex)))))

0 comments on commit b56a840

Please sign in to comment.