|
58 | 58 |
|
59 | 59 | (defn- get-global-context [] (first @!global-context))
|
60 | 60 |
|
61 |
| -(defonce pending-checks |
62 |
| - #?(:clj (java.util.concurrent.ArrayBlockingQueue. 10000) |
63 |
| - :cljs nil)) |
64 |
| - |
65 |
| - |
66 |
| -#?(:clj |
67 |
| - (defonce check-thread |
68 |
| - (doto (Thread. ^Runnable |
69 |
| - (fn [] |
70 |
| - (try |
71 |
| - ((.take ^java.util.concurrent.BlockingQueue pending-checks)) |
72 |
| - (catch #?(:clj Exception :cljs :default) _)) |
73 |
| - (recur)) |
74 |
| - "Guardrails Async") |
75 |
| - (.setDaemon true) |
76 |
| - (.start)))) |
77 |
| - |
78 | 61 | ;; runtime checking (both clj and cljs
|
79 | 62 | (defn- output-fn [data]
|
80 | 63 | (let [{:keys [level ?err msg_ ?ns-str ?file hostname_
|
|
113 | 96 | ((exp/custom-printer expound-options) explain-data))))
|
114 | 97 |
|
115 | 98 | (defn run-check [{:guardrails/keys [malli? compact? use-stderr? validate-fn explain-fn fqnm humanize-fn]
|
116 |
| - :keys [tap>? args? vararg? humanize-opts callsite throw? fn-name] |
| 99 | + :keys [tap>? args? vararg? humanize-opts throw? fn-name] |
117 | 100 | :as options}
|
118 | 101 | spec
|
119 | 102 | value]
|
|
138 | 121 | :guardrails/compact? compact?
|
139 | 122 | :guardrails/fqnm fqnm
|
140 | 123 | :guardrails/args? args?))
|
141 |
| - e (or callsite (ex-info "" {})) |
| 124 | + e (ex-info "" {}) |
142 | 125 | description (utils/problem-description
|
143 | 126 | (str
|
144 | 127 | "\nGuardrails:\n"
|
|
720 | 703 | :sym `(s/fdef ~fn-name ~@(generate-external-fspec bs false))
|
721 | 704 | :key `(s/def ~fn-name (s/fspec ~@(generate-external-fspec bs false))))))))
|
722 | 705 |
|
723 |
| -(defn callsite-exception [] |
724 |
| - #?(:cljs (js/Error. "") |
725 |
| - :clj (AssertionError. ""))) |
726 |
| - |
727 | 706 | ;; The now-nano was taken from taoensso/encore. I didn't want to include that entire dep just for this one
|
728 | 707 | ;; function. The are covered by Eclipse Public License - v 1.0. See https://github.com/taoensso/encore
|
729 | 708 | #?(:cljs (def ^:no-doc js-?window (when (exists? js/window) js/window))) ; Present iff in browser
|
|
776 | 755 | {max-checks-per-second :guardrails/mcps
|
777 | 756 | :guardrails/keys [use-stderr? compact? trace? stack-trace]
|
778 | 757 | :keys [throw? tap>? disable-exclusions?]} :config} cfg
|
779 |
| - {:guardrails/keys [validate-fn explain-fn humanize-fn malli?] |
780 |
| - :keys [async-checks?]} env |
| 758 | + {:guardrails/keys [validate-fn explain-fn humanize-fn malli?]} env |
781 | 759 | cljs? (cljs-env? env)
|
782 | 760 |
|
783 | 761 | {:com.fulcrologic.guardrails.core/keys
|
|
819 | 797 | exclusion-coord (if disable-exclusions?
|
820 | 798 | [:undefined/function :undefined]
|
821 | 799 | [(keyword nspc (name fn-name)) (keyword nspc)])
|
822 |
| - args-check (if #?(:clj async-checks? :cljs false) |
823 |
| - `(when-not (gr.cfg/-excluded? ~(first exclusion-coord) ~(second exclusion-coord)) |
824 |
| - (let [e# (callsite-exception)] |
825 |
| - (.offer |
826 |
| - ^java.util.concurrent.BlockingQueue pending-checks |
827 |
| - (fn [] |
828 |
| - (when ~argspec |
829 |
| - (run-check (assoc |
830 |
| - ~(assoc opts :args? true) |
831 |
| - :callsite e#) |
832 |
| - ~argspec |
833 |
| - ~arg-syms)))))) |
834 |
| - `(when ~argspec |
835 |
| - (when-not (gr.cfg/-excluded? ~(first exclusion-coord) ~(second exclusion-coord)) |
836 |
| - (run-check ~(assoc opts :args? true) ~argspec ~arg-syms)))) |
| 800 | + args-check `(when ~argspec |
| 801 | + (when-not (gr.cfg/-excluded? ~(first exclusion-coord) ~(second exclusion-coord)) |
| 802 | + (run-check ~(assoc opts :args? true) ~argspec ~arg-syms))) |
837 | 803 | retspec (gensym "retspec")
|
838 | 804 | ret (gensym "ret")
|
839 | 805 | add-throttling? (number? max-checks-per-second)
|
840 |
| - ret-check (if #?(:clj async-checks? :cljs false) |
841 |
| - `(when-not (gr.cfg/-excluded? ~(first exclusion-coord) ~(second exclusion-coord)) |
842 |
| - (let [e# (callsite-exception)] |
843 |
| - (.offer |
844 |
| - ^java.util.concurrent.BlockingQueue pending-checks |
845 |
| - (fn [] |
846 |
| - (when ~retspec |
847 |
| - (run-check (assoc |
848 |
| - ~(assoc opts :args? false) |
849 |
| - :callsite e#) |
850 |
| - ~retspec |
851 |
| - ~ret)))))) |
852 |
| - `(when (and ~retspec |
853 |
| - (not (gr.cfg/-excluded? ~(first exclusion-coord) ~(second exclusion-coord)))) |
854 |
| - (run-check ~(assoc opts :args? false) ~retspec ~ret))) |
| 806 | + ret-check `(when (and ~retspec |
| 807 | + (not (gr.cfg/-excluded? ~(first exclusion-coord) ~(second exclusion-coord)))) |
| 808 | + (run-check ~(assoc opts :args? false) ~retspec ~ret)) |
855 | 809 | real-function `(fn ~'guardrails-wrapper ~raw-arg-vec ~@body-forms)
|
856 | 810 | f (gensym "f")
|
857 | 811 | call (if (boolean conformed-var-arg)
|
|
946 | 900 | #?(:clj
|
947 | 901 | (defn >defn* [env form body {:keys [private? guardrails/malli?] :as opts}]
|
948 | 902 | (let [cfg (gr.cfg/get-env-config)
|
949 |
| - mode (gr.cfg/mode cfg) |
950 |
| - async? (gr.cfg/async? cfg)] |
| 903 | + mode (gr.cfg/mode cfg)] |
951 | 904 | (cond
|
952 | 905 | (not cfg) (clean-defn 'defn body)
|
953 | 906 | (#{:copilot :pro} mode) `(do
|
954 | 907 | (defn ~@body)
|
955 | 908 | ~(gr.pro/>defn-impl env body opts))
|
956 | 909 | (#{:runtime :all} mode)
|
957 |
| - (cond-> (remove nil? (generate-defn body private? (assoc env :form form :async-checks? async? :guardrails/malli? malli?))) |
| 910 | + (cond-> (remove nil? (generate-defn body private? (assoc env :form form :guardrails/malli? malli?))) |
958 | 911 | (cljs-env? env) clj->cljs
|
959 | 912 | (= :all mode) (-> vec (conj (gr.pro/>defn-impl env body opts)) seq))))))
|
960 | 913 |
|
|
0 commit comments