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

Trimming of maps in Cider causes evaluation of code to fail #2507

Closed
didibus opened this issue Nov 2, 2018 · 7 comments

Comments

Projects
None yet
2 participants
@didibus
Copy link

commented Nov 2, 2018

Expected behavior

Running

(edn/read-string
   (prn-str
    (let [map-size 101]
      (zipmap (range 0 map-size) (range 0 map-size)))))

Should return a map of 101 elements.

Actual behavior

In Cider, it instead throws

RuntimeException Map literal must contain an even number of forms clojure.lang.Util.runtimeException (Util.java:221)

This bug only happens inside Cider. Running this code in a normal Clojure REPL like lein repl with nRepl works as expected.

The reason it fails in Cider is that Cider trims the map as soon as it gets above 100 elements. Thus the map becomes unbalanced:

{10 10, 18 18, 105 105, 52 52, ...}

These ... are inserted by Cider when the map gets above 100 elements. You can see this by running:

(edn/read-string
   (prn-str
    (let [map-size 100]
      (zipmap (range 0 map-size) (range 0 map-size)))))

Which will return a map of 100 elements as normal.

It appears somehow that ciders modifies the string returned by prn-str, and makes it so that the edn map literal inside it is unbalanced, due to trimming.

Steps to reproduce the problem

Just run:

(edn/read-string
   (prn-str
    (let [map-size 101]
      (zipmap (range 0 map-size) (range 0 map-size)))))

Inside a Cider repl.

Environment & Version information

CIDER version information

;; CIDER 0.19.0snapshot (package: 20181030.2222), nREPL 0.2.12
;; Clojure 1.8.0, Java 1.8.0_192

Lein/Boot version

*Leiningen 2.8.1 on Java 1.8.0_192 OpenJDK 64-Bit Server VM

Emacs version

*GNU Emacs 25.1.1 (x86_64-redhat-linux-gnu, X toolkit, Xaw3d scroll bars) of 2016-10-19

Operating system

  • Linux
@bbatsov

This comment has been minimized.

Copy link
Member

commented Nov 3, 2018

CIDER sets *print-length* to 100 by default. Tweak this or set it to nil and it will be business as usual.

@didibus

This comment has been minimized.

Copy link
Author

commented Nov 4, 2018

Hum, that explains how the behavior affected Clojure code evaluation. Wouldn't there be a better way for Cider to limit the size of outputs from nRepl which wouldn't affect Clojure code evaluation?

If you see my example, nothing actually gets printed to Cider.

I understand Cider does this because Emacs performance on large prints is bad, and also maybe just good UX to not print huge things by default. But in a situation like my code snippet, it actually causes bugs in the code that arn't actually there.

So I wonder if instead of using print-length, nRepl couldn't just be made to trim the string it returns. So nothing in my code would break standard Clojure assumptions.

Regards

@bbatsov

This comment has been minimized.

Copy link
Member

commented Nov 5, 2018

Yeah, that's perfectly possible now. It just wasn't so possible when the workaround was added. :-) I can add a ticket on nREPL's end, but I'm overwhelmed with work, so I can't make any promises I'll get to it in the foreseeable future. Hopefully someone will pick it up.

@bbatsov

This comment has been minimized.

@didibus

This comment has been minimized.

Copy link
Author

commented Nov 6, 2018

Thanks, I don't think its a super high priority for now. I know you've been helping a bunch on many Clojure projects. Much appreciated! My employer isn't very OSS friendly, so I can't help much more then by reporting issues, writing blog posts, and helping out others unfortunately.

@stale

This comment has been minimized.

Copy link

commented May 8, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale label May 8, 2019

@bbatsov

This comment has been minimized.

Copy link
Member

commented May 14, 2019

This behaviour was changed in CIDER 0.21. Now it no longer sets *print-length* by default.

@bbatsov bbatsov closed this May 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.