Skip to content

Commit

Permalink
Don't crash on unknown function
Browse files Browse the repository at this point in the history
  • Loading branch information
vganshin committed Sep 13, 2019
1 parent fefa61a commit c0ba799
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/matcho.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,20 @@

(defn built-in-fn [fn-name]
(if-let [func (ns-resolve 'clojure.core (symbol fn-name))]
#( func %)
(throw (ex-info (str "Unknown function name '" fn-name "'") {:type :unknown-fn-name}))))
#(func %)
))

(defn str->fn [fn-name]
(if-let [fn (get fns fn-name)]
fn
(built-in-fn fn-name)))

(comment

(match {:a 1} {:a "number?"} )

(match {:a "hello"} {:a "#he\\w+"} )

)
(defn smart-explain-data [p x]
(cond

(and (string? p) (s/ends-with? p "?"))
(smart-explain-data (str->fn p) x)
(if-let [f (str->fn p)]
(smart-explain-data f x)
{:expected (str p " is not a function") :but x})

(and (string? p) (s/starts-with? p "#"))
(smart-explain-data (java.util.regex.Pattern/compile (subs p 1)) x)
Expand Down

0 comments on commit c0ba799

Please sign in to comment.