Skip to content

Commit 2c2d53a

Browse files
[print] Protect printing from broken eductions
1 parent 1fc3b38 commit 2c2d53a

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## master (unreleased)
44

5+
- [#359](https://github.com/clojure-emacs/orchard/pull/359): Print: protect printing from broken eductions.
6+
57
## 0.37.0 (2025-09-19)
68

79
- [#353](https://github.com/clojure-emacs/orchard/pull/353): Stacktrace: flag Clojure functions as duplicate.

src/orchard/print.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
(clojure.core Eduction)
1414
(clojure.lang AFunction Compiler IDeref IPending IPersistentMap MultiFn
1515
IPersistentSet IPersistentVector IRecord Keyword Namespace
16-
Symbol TaggedLiteral Var)
16+
RT Symbol TaggedLiteral Var)
1717
(java.io Writer)
18-
(java.util List Map Map$Entry)
18+
(java.util Iterator List Map Map$Entry)
1919
(mx.cider.orchard TruncatingStringWriter
2020
TruncatingStringWriter$TotalLimitExceeded)))
2121

@@ -78,8 +78,11 @@
7878
(when-not (nil? level)
7979
(set! *print-level* (dec level)))
8080
(try
81-
(let [^Iterable iterable (if (instance? Iterable x) x (seq x))
82-
it (.iterator iterable)]
81+
(let [^Iterator it (try (RT/iter (if (instance? Iterable x) x (seq x)))
82+
;; In some cases, calling .iterator may throw
83+
;; (e.g. incomplete CollReduce implementations).
84+
(catch Exception ex
85+
(RT/iter [(format "<<%s>>" ex)])))]
8386
(if (.hasNext it)
8487
(do (.write w prefix)
8588
(if (or (nil? level) (pos? level))

test/orchard/print_test.clj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(ns orchard.print-test
22
(:require
33
[clojure.test :as t :refer [is are deftest testing]]
4-
[orchard.print :as sut])
4+
[orchard.print :as sut]
5+
[orchard.test.util :refer [is+]])
56
(:import
67
(mx.cider.orchard TruncatingStringWriter
78
TruncatingStringWriter$TotalLimitExceeded)))
@@ -182,3 +183,13 @@
182183
(are [kw repr] (= repr (sut/print-str kw))
183184
::foo ":orchard.print-test/foo"
184185
::t/foo ":clojure.test/foo"))))
186+
187+
(deftest broken-eduction-test
188+
(testing "shouldn't throw if printing an eduction that lacks Seq impl"
189+
(is+ #"\(\"<<java.lang.IllegalArgumentException: Don't know how to create ISeq from:"
190+
(sut/print-str (eduction (map identity)
191+
(reify clojure.core.protocols.CollReduce
192+
(coll-reduce [_ f]
193+
(reduce f (range 10)))
194+
(coll-reduce [_ f init]
195+
(reduce f init (range 10)))))))))

0 commit comments

Comments
 (0)