Slamhound fails to reconstruct my ns forms

194 Views Asked by At

I have created a project with two namespaces, familja-moderne.core and familja-moderne.visualization.svg.

src/familja_moderne/core.clj

(ns familja-moderne.core
  (:require [clojure.set :as set])
  (:import (java.io ByteArrayInputStream)))

(def try-out
  [(set/map-invert
    {:1 :2
     :3 :4})
   (ByteArrayInputStream. (.getBytes "myBytes"))
   (familja-moderne.visualization.svg/points heists)])

src/familja_moderne/visualization/svg.clj

(ns familja-moderne.visualization.svg
  (:refer-clojure :exclude [max min]))

(def some-map {:this :that
               :foo :bar})

(def many-dependencies
  {:something (ByteArrayInputStream. (.getBytes "something"))
   :another-map (set/map-invert some-map)})

When I run

lein slamhound code/familja-moderne/src/familja_moderne/visualization/svg.clj

I get

WARNING: ex-info already refers to: #'clojure.core/ex-info in namespace: slingshot.ex-info, being replaced by: #'slingshot.ex-info/ex-info
WARNING: ex-data already refers to: #'clojure.core/ex-data in namespace: slingshot.ex-info, being replaced by: #'slingshot.ex-info/ex-data

which I don't understand but it works and my ns form is reconstructed as

(ns familja-moderne.visualization.svg
  (:require [clojure.set :as set])
  (:import (java.io ByteArrayInputStream))
  (:refer-clojure :exclude [max min]))

Running

lein slamhound code/familja-moderne/src/familja_moderne/core.clj

fails and I get the following messages

WARNING: ex-info already refers to: #'clojure.core/ex-info in namespace: slingshot.ex-info, being replaced by: #'slingshot.ex-info/ex-info
WARNING: ex-data already refers to: #'clojure.core/ex-data in namespace: slingshot.ex-info, being replaced by: #'slingshot.ex-info/ex-data
Failed to reconstruct: #<File code/familja-moderne/src/familja_moderne/core.clj>
java.lang.ClassNotFoundException: familja-moderne.visualization.svg, compiling:(NO_SOURCE_PATH:0:0)

Running

lein slamhound code/familja-moderne/src/familja_moderne/

which is supposed to reconstruct the ns forms in both namespaces results in something different

WARNING: ex-info already refers to: #'clojure.core/ex-info in namespace: slingshot.ex-info, being replaced by: #'slingshot.ex-info/ex-info
WARNING: ex-data already refers to: #'clojure.core/ex-data in namespace: slingshot.ex-info, being replaced by: #'slingshot.ex-info/ex-data
Failed to reconstruct: #<File code/familja-moderne/src/familja_moderne/core.clj>
Couldn't resolve familja-moderne.visualization.svg, got as far as {:import #{java.io.ByteArrayInputStream}, :alias {clojure.set set}, :old {:load nil, :exclude {}, :xrefer #{}, :require #{}, :refer-all #{}, :verbose #{}, :rename {}, :alias {clojure.set set}, :reload #{}, :reload-all #{}, :gen-class nil, :import #{java.io.ByteArrayInputStream}, :refer {}}, :meta nil, :name familja-moderne.core}

If I remove any reference to familja-moderne.visualization.svg from familja-moderne.core it works OK.

1

There are 1 best solutions below

0
On BEST ANSWER

I was having the same issue and opened a PR to Slamhound with a fix: https://github.com/technomancy/slamhound/pull/87.

You can try it by doing a lein install from the dotted-alias branch in my fork.

My theory is that this issue happens because of the clojure bug CLJ-1403 which makes the exception to be thrown when Slamhound is trying to "regrow" the ns form.

Hope that helps!