Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eval-on-point opened this issue Aug 9, 2024 · 9 comments

Comments

@eval-on-point
Copy link

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
Copy link

hiredman commented Aug 9, 2024

illegal-deps (filter #(illegal-dep? % interface-ns source) deps)]
looks like missing map of :to-brick-id or something similar?

@eval-on-point
Copy link
Author

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
Copy link
Collaborator

Will have a look.

@tengstrand
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link

hiredman commented Aug 9, 2024

I haven't repo'ed the error, just looking at the code

(defn deps-for-source [suffixed-top-ns interface-names base-names brick interface-ns source]
(let [deps (brick-deps-for-source suffixed-top-ns brick interface-names base-names source)
interface-deps (map :to-brick-id
(filter #(interface-dep? % interface-ns source)
deps))
base-deps (set/intersection (map :to-brick-id
(filter base? deps)))
illegal-deps (filter #(illegal-dep? % interface-ns source) deps)]
[(unique-ids interface-deps)
(unique-ids base-deps)
(unique-ids illegal-deps)]))

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
Copy link
Collaborator

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

tengstrand pushed a commit that referenced this issue Aug 9, 2024
@tengstrand tengstrand mentioned this issue Aug 9, 2024
tengstrand added a commit that referenced this issue Aug 9, 2024
Bug fix. Make sure we don't try to sort the vector of illegal dependencies (each dependency is a map). Issue #504
@eval-on-point
Copy link
Author

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

@tengstrand
Copy link
Collaborator

Thanks for setting up that extra repo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants