Improve ns access error message

This commit is contained in:
Scott Richmond 2022-04-25 19:23:32 -04:00
parent 4633941e08
commit 6f16495aab

View File

@ -135,7 +135,9 @@
(if (::data/struct map) (if (::data/struct map)
(if (contains? map kw) (if (contains? map kw)
(kw map) (kw map)
(throw (ex-info (str "Struct error: no member at " kw) {}))) (if (= (::data/type map) ::data/ns)
(throw (ex-info (str "Namespace error: no member " kw " in ns " (::data/name map)) {}))
(throw (ex-info (str "Struct error: no member at " kw) {}))))
(get map kw)) (get map kw))
))) )))
@ -177,20 +179,25 @@
(if (::data/struct target) (if (::data/struct target)
(if (contains? target kw) (if (contains? target kw)
(kw target) (kw target)
(throw (ex-info (str "Struct error: no member at " kw) {}))) (if (= (::data/type target) ::data/ns)
(throw (ex-info (str "Namespace error: no member " kw " in ns" (::data/name target)) {}))
(throw (ex-info (str "Struct error: no member at " kw) {}))
)
)
(kw target))) (kw target)))
(throw (ex-info "Called keywords take a single argument" {}))) (throw (ex-info "Called keywords take a single argument" {})))
:else (throw (ex-info "I don't know how to call that" {:fn lfn})))) :else (throw (ex-info "I don't know how to call that" {:fn lfn}))))
;; TODO: add placeholder partial application
(defn- interpret-synthetic-term [prev-value curr ctx] (defn- interpret-synthetic-term [prev-value curr ctx]
(let [type (::ast/type curr)] (let [type (::ast/type curr)]
(if (= type ::ast/atom) (if (= type ::ast/atom)
(if (::data/struct prev-value) (if (::data/struct prev-value)
(if (contains? prev-value (:value curr)) (if (contains? prev-value (:value curr))
(get prev-value (:value curr)) (get prev-value (:value curr))
(throw (ex-info (str "Struct error: no member " (:value curr)) {}))) (if (= (::data/type prev-value) ::data/ns)
(throw (ex-info (str "Namespace error: no member " (:value curr) " in ns " (::data/name prev-value)) {}))
(throw (ex-info (str "Struct error: no member " (:value curr)) {}))))
(get prev-value (:value curr))) (get prev-value (:value curr)))
(call-fn prev-value (interpret-ast curr ctx) ctx)))) (call-fn prev-value (interpret-ast curr ctx) ctx))))