From 09c519b18ec631c9a01be905a320062401485450 Mon Sep 17 00:00:00 2001 From: Stuart Sierra Date: Mon, 3 Jun 2013 10:01:47 -0400 Subject: [PATCH] A node may not depend on itself Also simplify generation of exception message. The *print-length* binding was paranoid: nodes should probably not be large data structures. Originally reported by "tgoossens" here: https://github.com/stuartsierra/dependency/pull/1 Also added to tools.namespace: https://github.com/clojure/tools.namespace/commit/41cd3c37cc29a4916d89aeca21ceac627a5174be --- src/com/stuartsierra/dependency.clj | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/com/stuartsierra/dependency.clj b/src/com/stuartsierra/dependency.clj index e3dd9c9..10d5a00 100644 --- a/src/com/stuartsierra/dependency.clj +++ b/src/com/stuartsierra/dependency.clj @@ -71,11 +71,9 @@ (set (keys dependents)))) DependencyGraphUpdate (depend [graph node dep] - (when (depends? graph dep node) - (let [^String msg (binding [*print-length* 10] - (str "Circular dependency between " - (pr-str node) " and " (pr-str dep)))] - (throw (Exception. msg)))) + (when (or (= node dep) (depends? graph dep node)) + (throw (Exception. (str "Circular dependency between " + (pr-str node) " and " (pr-str dep))))) (MapDependencyGraph. (update-in dependencies [node] set-conj dep) (update-in dependents [dep] set-conj node)))