polyfy / polylith

A tool used to develop Polylith based architectures in Clojure.
Eclipse Public License 1.0
523 stars 48 forks source link

Requiring multiple non-interface namespaces from another component throws java.lang.ClassCastException #504

Closed eval-on-point closed 3 months ago

eval-on-point commented 3 months ago

Describe the bug Requiring multiple non-interface namespaces from another component throws java.lang.ClassCastException.

To Reproduce This example repository shows a minimal example workspace that reproduces the error with instructions.

Expected behavior Instead of a stacktrace, I expect poly to give me multiple illegal dependency errors or otherwise not throw an error.

Additional context Found while trying to reproduce the error described in this Slack thread. This error does not seem to appear on version 0.2.19.

hiredman commented 3 months ago

https://github.com/polyfy/polylith/blob/adfcaa2789acad5d29a5d47ffeaeefd19672250a/components/deps/src/polylith/clj/core/deps/brick_deps/core.clj#L58 looks like missing map of :to-brick-id or something similar?

eval-on-point commented 3 months ago

Seems like it may not be reproducible on some systems (see this message in Slack). I've added a nix flake to the repo. This flake creates a devenv shell that reproduces the issue for me.

tengstrand commented 3 months ago

Will have a look.

tengstrand commented 3 months ago

I can't reproduce the error:

(comment
  (def source :src)
  (def interface-ns "top.")
  (def deps [{:from-type "component", :from-ns "interface", :to-type "library", :to-brick-id "component-two", :to-namespace "core"} 
             {:from-type "component", :from-ns "core", :to-type "library", :to-brick-id "component-two", :to-namespace "core"}])
  (filter #(illegal-dep? % interface-ns source) deps)
  #__)

The other two should do map :to-brick-id but not illegal-deps. I can't see what's wrong here, but maybe you can guide me.

tengstrand commented 3 months ago

Maybe you could clone the polylith repo and then point to it in an alias, which is described here. If the problem remains, then you have access to the polylith source code, so you can add print statements and the like, as a way to find what the problem is.

hiredman commented 3 months ago

I haven't repo'ed the error, just looking at the code https://github.com/polyfy/polylith/blob/adfcaa2789acad5d29a5d47ffeaeefd19672250a/components/deps/src/polylith/clj/core/deps/brick_deps/core.clj#L51-L61

deps on line 52 is a sequence of maps, interface-deps (line 53) is a sequence of whatever :to-brick-id is (presumably not a map), same for base-deps(line 56), but illegal-deps (line 58) remains a sequence of maps. so interface-deps sorts fine, base-deps sorts fine, but illegal-deps throws an error when trying to sort it (when it is non-empty).

tengstrand commented 3 months ago

Okay, thanks, now I get it! Will fix!

eval-on-point commented 3 months ago

Confirming that 2fca38b fixes the issue in both of my repos.

tengstrand commented 3 months ago

Thanks for setting up that extra repo!