From 47ffb78fccb44d62db29971dcb6e6d750869e1a7 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Wed, 15 May 2013 11:01:18 +1000 Subject: Change some error reporting stuff. Nothing major. --- src/clojure_sql/core.clj | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj index c829331..43e5089 100644 --- a/src/clojure_sql/core.clj +++ b/src/clojure_sql/core.clj @@ -184,9 +184,10 @@ {:table arg} {:table {arg arg}}))) -(defn ambiguous-error [field] - (throw (ex-info (str "Ambiguous field " field) - {:field field}))) +(defn ambiguous-error [field & [query]] + (throw (ex-info (str "Ambiguous field " field " in query with more than one table") + {:field field + :query query}))) (defn project [query fields] (let [table (if-not (:joins query) @@ -198,7 +199,7 @@ (or (get alias-lookup field nil) (if table [table field] - (ambiguous-error field)))))] + (ambiguous-error field query)))))] (assoc query :fields (->> (for [[key val] (if (map? fields) fields @@ -217,7 +218,7 @@ original-name (fn [field] (cond (vector? field) field (contains? alias-lookup field) (get alias-lookup field) - :else (throw (ex-info (str "Invalid field in rename: " (pr-str field)) + :else (throw (ex-info (str "Cannot rename field " (pr-str field) ". Field does not exist in query.") {:field field :query query :renames field-renames}))) @@ -342,6 +343,10 @@ (rename {:id :name :name :id}) deref) + (-> (table :users) + (project {:id :name + :name :id}) + deref) (-> (table :anotherStack) (project [:anotherNumber]) -- cgit v1.2.3