malli

DrLjótsson 2025-01-29T09:50:25.316519Z

I want to include malli.experimental.time but can't seem to register the schemas. Details in 🧵

✅ 1
DrLjótsson 2025-01-29T09:50:59.363199Z

I've added this to my core namespace

(malli.registry/set-default-registry!
   (malli.registry/composite-registry
    (m/default-schemas)
    (met/schemas)))

DrLjótsson 2025-01-29T09:51:32.360179Z

But then starting the app fails with

; Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:157).
; :malli.core/register-function-schema

DrLjótsson 2025-01-29T09:52:01.571129Z

I can however run this code from the REPL after the app has started and then the time schemas are registered

DrLjótsson 2025-01-29T09:52:29.337489Z

Any idea what is going on? Where should one place set-default-registry!

DrLjótsson 2025-01-29T09:54:59.126069Z

Update - registering the schema does not seem to be the problem!

DrLjótsson 2025-01-29T09:56:01.330219Z

It's when I use the :time/zoned-date-time in a top-level instrumentation of a function that I get the exception. Is the instrumentation running before the core namespace registers the time schemas?

DrLjótsson 2025-01-29T09:56:24.950289Z

I can run the instrumentation after the app has started and then everything works

DrLjótsson 2025-01-29T10:22:32.956819Z

Oh, nvm, the namespace that instruments the function needs to depend on the namespace that registers the time schemas.

DrLjótsson 2025-01-29T10:23:56.538529Z

How do people solve this generally? Seems easy to forget to require the namespace that does the registration everywhere where you instrument functions?

2025-01-29T16:33:14.154019Z

Even more generally if I need to ensure a top-level side effect has happened before evaluating something I use vars + linting. For example, here I would create a new namespace that sets the default registry, and expose tiny wrapper macros for all the operations I'd like to only happen after it has loaded. Then I use a linter to ban uses of the "raw" macros in my project.

;; my_app/malli.cljc
(ns my-app.malli
  (:require [malli.core :as m]))

(malli.registry/set-default-registry!
   (malli.registry/composite-registry
    (m/default-schemas)
    (met/schemas)))

;; now add a clj-kondo rule to ban malli.core/=> in my project
#?(:clj (defmacro => [& args] `(m/=> ~@args)))

DrLjótsson 2025-01-29T17:22:14.867529Z

Makes perfect sense, thanks!

👍 1
Wesley Matson (RemixAI work) 2025-01-29T23:45:55.195569Z

I just wanted to say thanks for making Malli! I had always avoided it before as “too fancy for me”, but it’s really working well for one of my current use cases. Particularly, I found myself needing to dynamically define schemae at runtime and generally treat them as a datatype of their own that can be operated upon.

💯 6
❤️ 2