From 8a16ae939d64dc23566baa131d85623df9d7be10 Mon Sep 17 00:00:00 2001 From: Daniel Higginbotham Date: Sat, 17 Feb 2024 15:50:46 -0500 Subject: [PATCH 1/2] support passing causes to -fail! --- src/malli/core.cljc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/malli/core.cljc b/src/malli/core.cljc index 0d872620e..8cee21979 100644 --- a/src/malli/core.cljc +++ b/src/malli/core.cljc @@ -133,11 +133,12 @@ (defn -deprecated! [x] (println "DEPRECATED:" x)) -(defn -exception [type data] (ex-info (str type) {:type type, :message type, :data data})) +(defn -exception [type data cause] (ex-info (str type) {:type type, :message type, :data data} cause)) (defn -fail! ([type] (-fail! type nil)) - ([type data] (throw (-exception type data)))) + ([type data] (-fail type data nil)) + ([type data cause] (throw (-exception type data cause)))) (defn -safe-pred [f] #(try (boolean (f %)) (catch #?(:clj Exception, :cljs js/Error) _ false))) From cc1ce46a64062abbcfb92f346d1b53b9aaaa1f90 Mon Sep 17 00:00:00 2001 From: Daniel Higginbotham Date: Sat, 17 Feb 2024 15:54:15 -0500 Subject: [PATCH 2/2] make cause optional in `-exception` --- src/malli/core.cljc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/malli/core.cljc b/src/malli/core.cljc index 8cee21979..5ce577b5a 100644 --- a/src/malli/core.cljc +++ b/src/malli/core.cljc @@ -133,11 +133,11 @@ (defn -deprecated! [x] (println "DEPRECATED:" x)) -(defn -exception [type data cause] (ex-info (str type) {:type type, :message type, :data data} cause)) +(defn -exception [type data & [cause]] (ex-info (str type) {:type type, :message type, :data data} cause)) (defn -fail! ([type] (-fail! type nil)) - ([type data] (-fail type data nil)) + ([type data] (-fail! type data nil)) ([type data cause] (throw (-exception type data cause)))) (defn -safe-pred [f] #(try (boolean (f %)) (catch #?(:clj Exception, :cljs js/Error) _ false)))