Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master (unreleased)

- [#359](https://github.com/clojure-emacs/orchard/pull/359): Print: protect printing from broken eductions.

## 0.37.0 (2025-09-19)

- [#353](https://github.com/clojure-emacs/orchard/pull/353): Stacktrace: flag Clojure functions as duplicate.
Expand Down
11 changes: 7 additions & 4 deletions src/orchard/print.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
(clojure.core Eduction)
(clojure.lang AFunction Compiler IDeref IPending IPersistentMap MultiFn
IPersistentSet IPersistentVector IRecord Keyword Namespace
Symbol TaggedLiteral Var)
RT Symbol TaggedLiteral Var)
(java.io Writer)
(java.util List Map Map$Entry)
(java.util Iterator List Map Map$Entry)
(mx.cider.orchard TruncatingStringWriter
TruncatingStringWriter$TotalLimitExceeded)))

Expand Down Expand Up @@ -78,8 +78,11 @@
(when-not (nil? level)
(set! *print-level* (dec level)))
(try
(let [^Iterable iterable (if (instance? Iterable x) x (seq x))
it (.iterator iterable)]
(let [^Iterator it (try (RT/iter (if (instance? Iterable x) x (seq x)))
;; In some cases, calling .iterator may throw
;; (e.g. incomplete CollReduce implementations).
(catch Exception ex
(RT/iter [(format "<<%s>>" ex)])))]
(if (.hasNext it)
(do (.write w prefix)
(if (or (nil? level) (pos? level))
Expand Down
13 changes: 12 additions & 1 deletion test/orchard/print_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns orchard.print-test
(:require
[clojure.test :as t :refer [is are deftest testing]]
[orchard.print :as sut])
[orchard.print :as sut]
[orchard.test.util :refer [is+]])
(:import
(mx.cider.orchard TruncatingStringWriter
TruncatingStringWriter$TotalLimitExceeded)))
Expand Down Expand Up @@ -182,3 +183,13 @@
(are [kw repr] (= repr (sut/print-str kw))
::foo ":orchard.print-test/foo"
::t/foo ":clojure.test/foo"))))

(deftest broken-eduction-test
(testing "shouldn't throw if printing an eduction that lacks Seq impl"
(is+ #"\(\"<<java.lang.IllegalArgumentException: Don't know how to create ISeq from:"
(sut/print-str (eduction (map identity)
(reify clojure.core.protocols.CollReduce
(coll-reduce [_ f]
(reduce f (range 10)))
(coll-reduce [_ f init]
(reduce f init (range 10)))))))))