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

Java Path value causes non-termination error in clerk/show! #199

Closed
respatialized opened this issue Aug 11, 2022 · 4 comments · Fixed by #201
Closed

Java Path value causes non-termination error in clerk/show! #199

respatialized opened this issue Aug 11, 2022 · 4 comments · Fixed by #201

Comments

@respatialized
Copy link

respatialized commented Aug 11, 2022

Previously reported on Clojurians; recording here for posterity as requested by @mk.

Description

Using java.nio.Path objects as values in a notebook causes a notebook to never successfully evaluate. It never reaches the Clerk evaluated 'src/clerk_errors.clj' in ... ms step.

Expected behavior

The notebook renders correctly using the string representation of a Path. Failing that, an error message is at least thrown somewhere so I don't have to manually interrupt notebook evaluation.

Reproducing the issue

(ns clerk-errors
  (:require [clojure.java.io :as io]
            [babashka.fs :as fs]
            [nextjournal.clerk :as clerk]))

;; Notebook demonstrating errors Clerk has with Java values
;;

;; # `Path`

(str (fs/path "something"))
(with-out-str (println (fs/path "something")))
;; String and printed representations work fine; the `Path` itself will cause values to hang.
; (fs/path "something")

If the above fs/path call is uncommented and evaluated with clerk/show!, the notebook hangs, never evaluating. Regular evaluation works fine.

@respatialized
Copy link
Author

respatialized commented Aug 11, 2022

@jackrusher also asked if I observe any browser console errors when this happens. I haven't seen any alongside this issue, in part because it doesn't seem to me like values are even getting across the JVM <> browser boundary.

@mk
Copy link
Member

mk commented Aug 12, 2022

@respatialized thanks for the report, I can reproduce it on my end.

@mk
Copy link
Member

mk commented Aug 15, 2022

The problem is nextjournal.clerk.analyzer/exceeds-bounded-count-limit? never terminating when getting a path:

(defn exceeds-bounded-count-limit? [x]
(reduce (fn [_ xs]
(try
(let [limit config/*bounded-count-limit*]
(if (and (seqable? xs) (<= limit (bounded-count limit xs)))
(reduced true)
false))
(catch Exception _e
(reduced true))))
false
(tree-seq seqable? seq x)))

See

(seq (.toPath (clojure.java.io/file "something")));;=> (#object[sun.nio.fs.UnixPath 0x5aa4c178 "something"])

(take 10 (tree-seq seqable? seq (.toPath (clojure.java.io/file "something"))))
;;=> (#object[sun.nio.fs.UnixPath 0x7307e110 "something"] #object[sun.nio.fs.UnixPath 0x35cacee7 "something"] #object[sun.nio.fs.UnixPath 0x3de508 "something"] #object[sun.nio.fs.UnixPath 0x4c185902 "something"] #object[sun.nio.fs.UnixPath 0xdb3ef0 "something"] #object[sun.nio.fs.UnixPath 0x630565fa "something"] #object[sun.nio.fs.UnixPath 0xc7fc937 "something"] #object[sun.nio.fs.UnixPath 0x22141f3 "something"] #object[sun.nio.fs.UnixPath 0x5b54d3f9 "something"] #object[sun.nio.fs.UnixPath 0x13b647dc "something"])

@mk
Copy link
Member

mk commented Aug 16, 2022

@respatialized the issue should be fixed with the commit above which just landed in main. Thanks again for the report.

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 a pull request may close this issue.

2 participants