Skip to content

fix: apply cider-print-quota to load-file requests#4113

Open
mmustafasenoglu wants to merge 2 commits into
clojure-emacs:masterfrom
mmustafasenoglu:fix/load-file-print-quota
Open

fix: apply cider-print-quota to load-file requests#4113
mmustafasenoglu wants to merge 2 commits into
clojure-emacs:masterfrom
mmustafasenoglu:fix/load-file-print-quota

Conversation

@mmustafasenoglu

Copy link
Copy Markdown

Problem

When using cider-eval-buffer / cider-load-buffer, the evaluation result of the last form is displayed in the echo area via cider--display-interactive-eval-result. If this result is large (e.g., a deep map or huge string), Emacs freezes or crashes because the full result is sent to the echo area.

While cider-print-quota (default 1 MB) truncates results for eval requests, the load-file op used by cider-load-buffer did not include the print middleware parameters, so cider-print-quota was not enforced.

Fix

Add cider--nrepl-print-request-plist to the load-file request in cider-load-file-request, so that cider-print-quota, cider-print-fn, and other print settings are honored — matching the behavior of eval requests.

Before:

(cider-nrepl-send-request `("op" "load-file"
                            "file" ,file-contents
                            "file-path" ,file-path
                            "file-name" ,file-name)
                          ...)

After:

(cider-nrepl-send-request `("op" "load-file"
                            "file" ,file-contents
                            "file-path" ,file-path
                            "file-name" ,file-name
                            ,@(cider--nrepl-print-request-plist))
                          ...)

Why this works

cider--nrepl-print-request-plist already provides all the standard print middleware parameters:

  • nrepl.middleware.print/quotacider-print-quota (default 1 MB)
  • nrepl.middleware.print/printcider-print-fn
  • nrepl.middleware.print/stream? → streaming flag
  • nrepl.middleware.print/buffer-sizecider-print-buffer-size
  • nrepl.middleware.print/options → other print options

These parameters were already being sent for eval requests but were missing from the load-file request path.

Related issue

Fixes #3052

The load-file op did not include print middleware parameters
(nrepl.middleware.print/quota, etc.), so cider-print-quota was
not enforced when evaluating buffers via cider-eval-buffer /
cider-load-buffer.  Large evaluation results were sent in full
to the echo area, which could freeze or crash Emacs.

Add the standard cider--nrepl-print-request-plist to the
load-file request so that cider-print-quota (default 1 MB)
is honored, matching the behavior of eval requests.

Fixes clojure-emacs#3052

Signed-off-by: Mustafa Senoglu <mmustafasenoglu0@gmail.com>

@bbatsov bbatsov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this is a real gap. load-file sends no print params, so the last form's value comes back unbounded (I checked against a live server: a modest map came back at 82KB, and it can be much bigger), while eval bounds it via the quota. I confirmed load-file does honor the quota when we send it, so the approach is sound.

One change I'd want before merging (inline), and I'd keep #3052 open rather than close it. That issue is really about making the result destination configurable (send it to the REPL, or nowhere), which this doesn't add. Bounding the size fixes the crash, which is worth doing on its own, but it's a different thing from what the reporter asked for, so maybe reword to "Addresses #3052". A test asserting the load-file request carries the quota would be good too.

Comment thread lisp/cider-client.el Outdated
"file-path" ,file-path
"file-name" ,file-name)
"file-name" ,file-name
,@(cider--nrepl-print-request-plist))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd reach for cider--nrepl-pr-request-plist here instead. The eval commands that echo their result to the minibuffer (cider-eval-last-sexp, cider-eval-region) use the pr variant, and it carries the quota too, so it fixes the crash while keeping the echoed result single-line and consistent with eval. cider--nrepl-print-request-plist would switch load-file's result to pretty-printed and streamed, which is a behavior change I don't think we want on this path.

Comment thread lisp/cider-client.el Outdated
(provide 'cider-client)

;;; cider-client.el ends here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray trailing newline, drop this.

-  → 
  (pr variant keeps echoed result single-line, consistent with eval)
- Remove stray trailing newline at end of file

Requested by @bbatsov
@mmustafasenoglu

Copy link
Copy Markdown
Author

Done. Thanks for the review!

  • cider--nrepl-print-request-plistcider--nrepl-pr-request-plist (pr variant keeps echoed result single-line and consistent with eval commands)
  • Removed the stray trailing newline

@bbatsov

bbatsov commented Jul 20, 2026

Copy link
Copy Markdown
Member

Thanks, the code looks good now. One last thing before I merge: could you change "Fixes #3052" to "Addresses #3052" in the description? That issue is really about making the result destination configurable (send it to the REPL, or nowhere), which this doesn't add, so I'd rather it not auto-close on merge. After that this is good to go.

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

Successfully merging this pull request may close these issues.

"cider-eval-buffer" cannot be configured to *not* send evaluation result to echo area

2 participants