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

Ignore dependencies for namespaces that use/require themselves. #14

Merged
merged 1 commit into from
May 22, 2014

Conversation

ragnard
Copy link
Contributor

@ragnard ragnard commented Oct 30, 2013

This commit prevents a StackOverflowError that will occur when computing
transitive dependencies for a namespace that depends on itself.

Clojure currently allows namespace declarations that use/require itself:

(ns x
  (:require [x]))

ns-tracker adds these as dependencies in its graph but blows up with a StackOverflowError when calculating transitive dependencies.

This proposed fix simply ignores such dependencies, much like the clojure ns macro does.

Having self-referential namespaces is obviously wrong, but since the problem is not caught by the ns macro it is very hard to debug when it blows up in ns-tracker.

@ragnard
Copy link
Contributor Author

ragnard commented May 21, 2014

This was problem was encountered again in the wild by a colleague of mine. Any chance of considering the patch?

@weavejester
Copy link
Owner

Rather than ignore the self-referential dependency, it might be better just to add a check to the precondition. This would make the system fail in a way that's easier to debug.

The change would also need a test.

@ragnard
Copy link
Contributor Author

ragnard commented May 22, 2014

Thanks for the feedback. I've updated the patch to use a pre-condition and added tests.

I can't say I'm extremely fond of using pre-conditions in this case, since all the user of this library will see is:

java.lang.AssertionError: Assert failed: (not (= dep x))

which doesn't tell them anything about what they've done wrong and requires intimate knowledge of the ns-tracker library to understand.

@weavejester
Copy link
Owner

What about changing the preconditions into asserts with messages, e.g.

(assert (not (depends? graph dep x)) "circular dependency")
(assert (not (= x dep)) "self-referential dependency")

This prevents a StackOverflowError that will occur when computing
transitive dependencies for a namespace that depends on itself.
@ragnard
Copy link
Contributor Author

ragnard commented May 22, 2014

I was very close to doing exactly that, but I didn't want to change too much. I think that's a slightly more user friendly solution. Pull request updated.

@weavejester
Copy link
Owner

Excellent, thanks

weavejester added a commit that referenced this pull request May 22, 2014
Forbid namespaces that use/require themselves
@weavejester weavejester merged commit c76ef53 into weavejester:master May 22, 2014
@ragnard
Copy link
Contributor Author

ragnard commented May 22, 2014

Thank you for taking the time!

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

Successfully merging this pull request may close these issues.

2 participants