From 00b20f6bbfa432345131036ce3a5d8bf6a9df628 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Thu, 17 Jun 2021 12:54:15 -0700 Subject: [PATCH] Address #330 by improving exception --- CHANGELOG.md | 3 +++ src/honey/sql.cljc | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bca889a..582bb1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changes +* 2.0.next in progress + * Address #330 by improving exception when a non-entity is encountered where an entity is expected. + * 2.0.0-rc3 (for testing; 2021-06-16) * Fix #328 by adding `:distinct` as special syntax, affecting an expression. * Address #327 by changing "unknown clause" error to including mention of "nil values" (which are also illegal). diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 5ff4375..bcbd21a 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -151,8 +151,27 @@ (keyword (name s))) s)) -(defn- namespace-_ [x] (some-> (namespace x) (str/replace "-" "_"))) -(defn- name-_ [x] (str/replace (name x) "-" "_")) +(defn- namespace-_ + "Return the namespace portion of a symbol, with dashes converted." + [x] + (try + (some-> (namespace x) (str/replace "-" "_")) + (catch Throwable t + (throw (ex-info (str "expected symbol, found: " + (type x)) + {:symbol x + :failure (ex-message t)}))))) + +(defn- name-_ + "Return the name portion of a symbol, with dashes converted." + [x] + (try + (str/replace (name x) "-" "_") + (catch Throwable t + (throw (ex-info (str "expected symbol, found: " + (type x)) + {:symbol x + :failure (ex-message t)}))))) (defn- sqlize-value [x] (cond