Skip to content

Custom middleware broke last update #3826

Open
@archaic

Description

@archaic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions