Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty Printer StackOverflows on schema #1149

Open
iwillig opened this issue Dec 13, 2024 · 1 comment
Open

Pretty Printer StackOverflows on schema #1149

iwillig opened this issue Dec 13, 2024 · 1 comment

Comments

@iwillig
Copy link

iwillig commented Dec 13, 2024

Hello, been enjoying learning malli. Thanks for making it.

I am trying to add schema to a rather large code based and running into some issues with the error pretty printer. See error below.

Here are the relevant schema parts, and function definition and error.

We have a fairly complicated internal system that is not easy to share, but I want to do call out this might be related to our system. I will work on isolating this in a new repo.

Schema

Function in question,

(defn gen-tx-data-add-main
  [{:as _ctx :keys [db now organization2-id workspace2-id]}
   story-id comment-tempid author-id params]
    ;; code ommited 
   [{:db/id comment-tempid} 
    [:db/add story :story/comments comment-tempid]
     ;; ... extra tx-data ommited 
     ])

Annonation

(malli/=> gen-tx-data-add-main
          [:->
           #'ms/BaseAppContext
           #'ms/DbId
           #'ms/TempId
           #'ms/DbId
           #'ms/CommentAddInputs
           #'ms/DatomicTxData])

Relevant schemas

(ns ms
   (:require [malli.util :as malli.util]
             [private-thing :as entity)

;; entity/all-types returns a promise that I deref here. unusual. 

(def
  EntityTypes
  (concatv
   [:enum]
   (mapv :ident (deref entity/all-types))))

(def 
  DbId
  pos-int?)

(def
  TempId
  [:map {:closed false}
   [:part                keyword?]
   [:idx                 neg-int?]
   [::entity/entity-type EntityTypes]
   [::entity/entity-key  uuid?]])

(def
  Id
  [:or #'TempId #'DbId])

(def 
  Ids
  [:seqable #'Id])

(def 
  DbIds
  [:seqable #'DbId])

(def 
  DatomicOperation
  keyword?)

(def
  DatomicValue
  [:or string? boolean? number? keyword? uuid? vector? inst? #'Id])

(def 
  DatomicAttribute
  keyword?)

(def
  DatomicTuple
  [:tuple #'DatomicOperation #'Id #'DatomicAttribute #'DatomicValue])

(def
  DatomicRetract
  [:tuple #'DatomicOperation #'Id #'DatomicAttribute])

(def
  DatomicCas
  [:tuple
   #'DatomicOperation
   #'Id
   #'DatomicAttribute
   [:maybe #'DatomicValue]
   [:maybe #'DatomicValue]])

(def
  DatomicAddMap
  [:map
   {:closed false}
   [:db/id #'TempId]])

(def TxFnRetractIfResolve
  [:tuple any? number? keyword?])

(def TxFnPrepend-7
  [:tuple any? number? number? keyword? number? keyword? vector?])

(def TxFnInsertItemAtEdge-5
  [:tuple symbol? keyword? keyword? number? vector?])

(def TxFnInsertItemAtEdge-6
  [:tuple symbol? keyword? keyword? number? number? vector?])

(def TxnInsertPosition-9
  [:tuple symbol? number? number? keyword? number? keyword? [:or number? vector?] keyword? #'Id])

(def TxLargeString
  [:tuple keyword? keyword? any?])
(def ChRule
  [:or
   [:tuple keyword? keyword? #'Id keyword? any?]
   [:tuple keyword? keyword? #'Id #'Id keyword? keyword? any?]])

(def 
  DatomicTxExp
  [:or
   #'DatomicTuple
   #'DatomicAddMap
   #'DatomicCas
   #'DatomicRetract
   #'TxFnPrepend-7
   #'ChRule
   #'TxFnRetractIfResolve
   #'TxFnInsertItemAtEdge-5
   #'TxFnInsertItemAtEdge-6
   #'TxnInsertPosition-9
   #'TxLargeString])

(def
  DatomicTxData
  [:sequential #'DatomicTxExp])

(def DatomicDB
  [:fn (partial instance? Database)])

(def BaseAppContext
  [:map {:closed false}
   [:now inst?]
   [:db  #'DatomicDB]])

(def CommentAddInputs
  [:map {:closed false}
   [:text                              string?]
   [:creatd_at        {:optional true} inst?]
   [:updated_at       {:optional true} inst?]
   [:ch/position      {:optional true} number?]
   [:external_id      {:optional true} string?]
   [:slack_message_ts {:optional true} string?]
   [:slack_channel    {:optional true} string?]])

Error

  Show: Project-Only All 
  Hide: Clojure Java REPL Tooling Duplicates  (64 frames hidden)

1. Unhandled java.lang.StackOverflowError
   (No message)

    PersistentHashMap.java:  154  clojure.lang.PersistentHashMap/valAt
    PersistentHashMap.java:  158  clojure.lang.PersistentHashMap/valAt
              MultiFn.java:  147  clojure.lang.MultiFn/getMethod
              MultiFn.java:  154  clojure.lang.MultiFn/getFn
              MultiFn.java:  233  clojure.lang.MultiFn/invoke
                  core.clj: 3700  clojure.core/pr-on
                  core.clj: 3703  clojure.core/pr
                  core.clj: 3703  clojure.core/pr
                  AFn.java:  154  clojure.lang.AFn/applyToHelper
               RestFn.java:  135  clojure.lang.RestFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 4785  clojure.core/pr-str
                  core.clj: 4785  clojure.core/pr-str
               RestFn.java:  411  clojure.lang.RestFn/invoke
                virhe.cljc:   62  malli.dev.virhe.EdnPrinter/visit_keyword
                visit.cljc:   42  fipp.visit$visit_STAR_/invokeStatic
                visit.cljc:   32  fipp.visit$visit_STAR_/invoke
                visit.cljc:   61  fipp.visit$visit/invokeStatic
                visit.cljc:   58  fipp.visit$visit/invoke
                  edn.cljc:   13  fipp.edn$pretty_coll$fn__168293/invoke
                  core.clj: 2759  clojure.core/map/fn/fn
  TransformerIterator.java:   79  clojure.lang.TransformerIterator/step
  TransformerIterator.java:   97  clojure.lang.TransformerIterator/hasNext
                   RT.java:  537  clojure.lang.RT/chunkIteratorSeq
                  core.clj: 2679  clojure.core/sequence

Thanks for your time.

@iwillig
Copy link
Author

iwillig commented Dec 13, 2024

I tried replacing all of my custom schemas with any? and rerunning the function with malli. I got the same failure.

(malli/=> gen-tx-data-add-main
          [:->
           any?
           any?
           any?
           any?
           any?
           any?])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant