cider icon indicating copy to clipboard operation
cider copied to clipboard

Custom middleware broke last update

Open archaic opened this issue 4 months ago • 0 comments

The lateset update to 0.56.0 broke some custom middleware I have been using (shown below)


(:require
   [cider.nrepl.middleware]
   [nrepl.middleware]
   [nrepl.server]
   [refactor-nrepl.middleware]
   [taoensso.telemere :as t])

(defn wrap-print-limit
  [handler]
  (fn [{:as msg
        :nrepl.middleware.print/keys [options]
        :keys [op session]}]

    (when (and (#{"eval"} op)
               session)

      (if (instance? clojure.lang.IAtom session)
        (swap! session
               (fn [state]
                 (-> state
                    (assoc #'clojure.core/*print-length*
                           (or (get options :length)
                               (get options :max-length)
                               52))

                    (assoc #'clojure.core/*print-level*
                           (or (get options :level)
                               (get options :max-depth)
                               10)))))

        (t/error! {:data session
                   :msg "session is not an atom"})))

    (handler msg)))

(nrepl.middleware/set-descriptor! #'wrap-print-limit
                                  {:description "overwrites *print-length* and *print-level* in :session"
                                   :expects #{"eval"}
                                   :requires #{"session"}})

(defn nrepl-handler
  []
  (apply nrepl.server/default-handler
         (into cider.nrepl.middleware/cider-middleware
               [#'refactor-nrepl.middleware/wrap-refactor
                #'wrap-print-limit])))

Using Zprint, I have been using this setup for a while, it broke in the last update (55.7 to 56.0 I think) (the error condition is being hit, and session is not an atom)

I use this setup so that I can dynamically set print options in emacs and have it immedately work in the repl, also I have some custom eval code that I bind that uses print-length and print-level so I want that updated along with the zprint variables.

Is there something fundamentally I am doing wrong, or did something change in regards to :expects and :requires?

Everything is absolute latest (emacs git-master + doom, java is 24.0.1, OS arch-linux current)

Thanks, Chris Rosengren

archaic avatar May 29 '25 21:05 archaic