Skip to content
Browse files

data_readers.clj should contain a legal Clojure map, not an ad hoc da…

…ta structure
  • Loading branch information...
1 parent 4036c77 commit 28618bbfa870fcbd68cce36b531ca56b02df4a36 @stuarthalloway stuarthalloway committed Mar 13, 2012
Showing with 23 additions and 20 deletions.
  1. +23 −20 src/clj/clojure/core.clj
View
43 src/clj/clojure/core.clj
@@ -6613,13 +6613,6 @@
(.. Thread currentThread getContextClassLoader
(getResources "data_readers.clj"))))
-(defn- assert-symbol [^clojure.lang.LineNumberingPushbackReader reader x]
- (when-not (symbol? x)
- (throw (ex-info "non-symbol in data-reader file"
- {:file *file*
- :line (.getLineNumber reader)
- :value x}))))
-
(defn- data-reader-var [sym]
(intern (create-ns (symbol (namespace sym)))
(symbol (name sym))))
@@ -6629,23 +6622,33 @@
(java.io.InputStreamReader.
(.openStream url) "UTF-8"))]
(binding [*file* (.getFile url)]
- (loop [mappings mappings]
- (if-let [tag (read rdr false nil)]
- (do (assert-symbol rdr tag)
- (when (contains? mappings tag)
- (throw (ex-info "Conflicting data-reader mapping"
- {:file *file*
- :line (.getLineNumber rdr)
- :symbol tag})))
- (let [target (read rdr true nil)]
- (assert-symbol rdr target)
- (recur (assoc mappings tag (data-reader-var target)))))
- mappings)))))
+ (let [new-mappings (read rdr false nil)]
+ (when (not (map? new-mappings))
+ (throw (ex-info (str "Not a valid data-reader map")
+ {:url url})))
+ (reduce
+ (fn [m [k v]]
+ (when (not (symbol? k))
+ (throw (ex-info (str "Invalid form in data-reader file")
+ {:url url
+ :form k})))
+ (when (contains? mappings k)
+ (throw (ex-info "Conflicting data-reader mapping"
+ {:url url
+ :conflict k
+ :mappings m})))
+ (assoc m k (data-reader-var v)))
+ mappings
+ new-mappings)))))
(defn- load-data-readers []
(alter-var-root #'*data-readers*
(fn [mappings]
(reduce load-data-reader-file
mappings (data-reader-urls)))))
-(load-data-readers)
+(try
+ (load-data-readers)
+ (catch Throwable t
+ (.printStackTrace t)
+ (throw t)))

0 comments on commit 28618bb

Please sign in to comment.
Something went wrong with that request. Please try again.