Fail fast during app initialization if an invalid schema is found (#19958)

Some devs reported invalid schemas in the develop branch during app
initialization. We knew this could happen when Malli was first
introduced, but we wanted to play safe in the beginning due to the
overall inexperience of the team with Malli.

This commit removes all guardrails on instrumented vars, i.e. during app
initialization the app will crash on any invalid schema. A reminder that
instrumentation only take effect when js/goog.DEBUG is true.
This commit is contained in:
Icaro Motta 2024-05-10 09:12:31 -03:00 committed by GitHub
parent a68b2f357d
commit a481a44c72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 18 deletions

View File

@ -12,8 +12,8 @@
[:lower-case? :boolean]
[:upper-case? :boolean]
[:numbers? :boolean]
[:symbols? :boolean]]
[:any]]])
[:symbols? :boolean]]]
:any])
(defn- view-internal
[{:keys [lower-case? upper-case? numbers? symbols?]}]

View File

@ -19,5 +19,5 @@
(catch js/Error e#
(taoensso.timbre/error "Failed to instrument function"
{:symbol ~sym :error e#})
~sym))
(throw e#)))
~sym))

View File

@ -91,5 +91,5 @@
{:schema-id schema-id
:error e
:function f})
f))
(throw e)))
f)))

View File

@ -90,19 +90,12 @@
manually call `setup!`, otherwise you won't see any changes. It is safe and
even expected you will call `setup!` multiple times in REPLs."
[]
(try
(schema.registry/init-global-registry)
(register-schemas)
(schema.registry/init-global-registry)
(register-schemas)
;; In theory not necessary, but sometimes in a REPL session the dev needs to
;; call unstrument! manually.
(malli.instrument/unstrument!)
;; In theory not necessary, but sometimes in a REPL session the dev needs to
;; call unstrument! manually.
(malli.instrument/unstrument!)
(malli.dev/start! {:report (schema/reporter)})
(log/debug "Schemas initialized.")
;; It is relatively easy to write invalid schemas, but we don't want to
;; block the app from initializing if such errors happen, at least not until
;; Malli matures in the project.
(catch js/Error e
(log/error "Failed to initialize schemas" {:error e}))))
(malli.dev/start! {:report (schema/reporter)})
(log/debug "Schemas initialized."))