Skip to content

Commit e0bc0a7

Browse files
committed
Add optional jvm option to only check frame schema in development
1 parent ad72c48 commit e0bc0a7

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

deps.edn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
:run {:main-opts ["-m" "simulflow.transport.local.audio"]
3434
:exec-fn simulflow.transport.local.audio/main}
3535
:dev {:extra-paths ["dev"]
36+
;; Check schema for each frame instantiation (not recommended in prod
37+
;; since many schemas are created)
38+
:jvm-opts ["-Dsimulflow.frame.schema-checking=true"]
3639
:extra-deps {djblue/portal {:mvn/version "0.58.5"}
3740
criterium/criterium {:mvn/version "0.4.6"}
3841
clj-kondo/clj-kondo {:mvn/version "2024.11.14"}}}

src/simulflow/frame.clj

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
(defrecord Frame [type data ts])
1010

11+
(def check-frame-schema?
12+
"Whether the schema of frames should be checked on schema creation. Use
13+
alias :dev to make this true. Default false"
14+
(try
15+
(Boolean/parseBoolean (System/getProperty "simulflow.frame.schema-checking" "false"))
16+
(catch Exception e
17+
false)))
18+
1119
(defn frame? [frame]
1220
(instance? Frame frame))
1321

@@ -56,10 +64,11 @@
5664
(fn
5765
[data#]
5866
(let [frame# (create-frame ~type data#)]
59-
(when-let [err# (me/humanize (m/explain ~frame-schema frame#))]
60-
(throw (ex-info "Invalid frame data"
61-
{:error err#
62-
:frame frame#})))
67+
(when check-frame-schema?
68+
(when-let [err# (me/humanize (m/explain ~frame-schema frame#))]
69+
(throw (ex-info "Invalid frame data"
70+
{:error err#
71+
:frame frame#}))))
6372
frame#)))
6473

6574
;; Define the predicate function

0 commit comments

Comments
 (0)