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

clojure.java.io/file throws Unhandled REPL handler exception processing message #534

Closed
taylskid opened this issue Jun 15, 2018 · 17 comments

Comments

@taylskid
Copy link

taylskid commented Jun 15, 2018

Expected behavior

user> (clojure.java.io/file "/Users/taylorskidmore/foo.json")
user> (slurp (clojure.java.io/file "/Users/taylorskidmore/foo.json"))
""

Actual behavior

ERROR: Unhandled REPL handler exception processing message {:op slurp, :url file:/Users/taylorskidmore/foo.json, :session 6dfeb733-5821-43e2-9f7e-fa952127297d, :id 11}
java.lang.NullPointerException
	at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
	at java.util.regex.Matcher.reset(Matcher.java:309)
	at java.util.regex.Matcher.<init>(Matcher.java:229)
	at java.util.regex.Pattern.matcher(Pattern.java:1093)
	at clojure.core$re_matcher.invokeStatic(core.clj:4674)
	at clojure.core$re_find.invokeStatic(core.clj:4716)
	at clojure.core$re_find.invoke(core.clj:4716)
	at cider.nrepl.middleware.slurp$normalize_content_type.invokeStatic(slurp.clj:55)
	at cider.nrepl.middleware.slurp$normalize_content_type.invoke(slurp.clj:50)
	at cider.nrepl.middleware.slurp$slurp_url_to_content_PLUS_body.invokeStatic(slurp.clj:92)
	at cider.nrepl.middleware.slurp$slurp_url_to_content_PLUS_body.invoke(slurp.clj:85)
	at cider.nrepl.middleware.slurp$handle_slurp.invokeStatic(slurp.clj:124)
	at cider.nrepl.middleware.slurp$handle_slurp.invoke(slurp.clj:114)
	at clojure.lang.Var.invoke(Var.java:383)
	at cider.nrepl$wrap_slurp$fn__1441.invoke(nrepl.clj:139)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_stacktrace$fn__1573.invoke(nrepl.clj:425)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_classpath$fn__1457.invoke(nrepl.clj:155)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__693.invoke(interruptible_eval.clj:247)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at clojure.tools.nrepl.middleware.session$add_stdin$fn__774.invoke(session.clj:238)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at clojure.tools.nrepl.middleware.load_file$wrap_load_file$fn__817.invoke(load_file.clj:79)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_out$fn__1533.invoke(nrepl.clj:325)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_debug$fn__1475.invoke(nrepl.clj:181)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_enlighten$fn__1483.invoke(nrepl.clj:207)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_content_type$fn__1433.invoke(nrepl.clj:128)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_inspect$fn__1509.invoke(nrepl.clj:244)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_pprint$fn__1423.invoke(nrepl.clj:108)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at clojure.tools.nrepl.middleware.pr_values$pr_values$fn__611.invoke(pr_values.clj:22)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_test$fn__1581.invoke(nrepl.clj:435)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl.middleware.pprint$handle_pprint_fn.invokeStatic(pprint.clj:49)
	at cider.nrepl.middleware.pprint$handle_pprint_fn.invoke(pprint.clj:44)
	at clojure.lang.Var.invoke(Var.java:383)
	at cider.nrepl$wrap_pprint_fn$fn__1413.invoke(nrepl.clj:89)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at cider.nrepl$wrap_tracker$fn__1597.invoke(nrepl.clj:473)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at clojure.tools.nrepl.middleware.session$session$fn__759.invoke(session.clj:192)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__424.invoke(middleware.clj:22)
	at clojure.tools.nrepl.server$handle_STAR_.invokeStatic(server.clj:19)
	at clojure.tools.nrepl.server$handle_STAR_.invoke(server.clj:16)
	at clojure.tools.nrepl.server$handle$fn__830.invoke(server.clj:28)
	at clojure.core$binding_conveyor_fn$fn__4676.invoke(core.clj:1938)
	at clojure.lang.AFn.call(AFn.java:18)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
 (clojure.java.io/file "/Users/taylorskidmore/foo.json")

Steps to reproduce the problem

Call clojure.java.io/file on a file in the repl

Environment & Version information

cider-nrepl version

0.18.0-SNAPSHOT (head)

Java version

1.8

Operating system

Mac OS X (10.13.5)

@taylskid
Copy link
Author

This is being caused by get-file-content returning nil and being passed into re-find in normalize-content-type in cider.nrepl.middleware.slurp. I have a patch working locally that I can PR if you'd like

@bbatsov
Copy link
Member

bbatsov commented Jun 15, 2018 via email

@taylskid
Copy link
Author

@bbatsov I actually am having trouble with one of the tests: test-sum-types-is-base64. I tried renaming a random jpg I had to "sum-types-are-cool.jpg" and threw into the resources folder but it's still failing. Files/probeContentType is returning nil. Do I need a specific type of jpg?

@bbatsov
Copy link
Member

bbatsov commented Jun 16, 2018

I'll defer here to @arrdem.

@arrdem
Copy link
Contributor

arrdem commented Jun 17, 2018

Sorry I didn't notice this - my GH notification fatigue is real atm.

@taylskid AFAIK you shouldn't need to do anything specific, I thought I included the "sum types are cool" png in my original CIDER pr so it should just be in the repo. If it's not, I'd be happy to provide the one I developed against ;)

This bug rots, but isn't super surprising. I think I've encountered this behavior as well. It may well be appropriate to add an extra layer of content-type guessing on the CIDER side of things, since there's a very short whitelist of supported content-types ATM.

@bbatsov bbatsov added the bug label Sep 16, 2018
@bbatsov
Copy link
Member

bbatsov commented Sep 16, 2018

@taylskid Any update here?

@sundbp
Copy link

sundbp commented Oct 16, 2018

I just ran into this as well fwiw, when doing e.g. (io/file "/path/ending/in/a/dir")

@pdenno
Copy link
Contributor

pdenno commented Jul 28, 2019

I think this is still a problem. I get it with (io/file ".") and pretty much anything other directory argument. Works when the argument is a file.

@mrrodriguez
Copy link

I noted this on the slack channel, but this is related in the error, but not in the issue with directories mentioned above:

(URL. "http://www.admin.ch/ch/e/rs/c221_302.html")

;; causes

;; ERROR: Unhandled REPL handler exception processing message {:op slurp, :url http://www.admin.ch/ch/e/rs/c221_302.html, :session <id>, :id <id>}

Relevant stack trace:

java.lang.NullPointerException
	at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
	at java.util.regex.Matcher.reset(Matcher.java:309)
	at java.util.regex.Matcher.<init>(Matcher.java:229)
	at java.util.regex.Pattern.matcher(Pattern.java:1093)
	at clojure.core$re_matcher.invokeStatic(core.clj:4856)
	at clojure.core$re_find.invokeStatic(core.clj:4898)
	at clojure.core$re_find.invoke(core.clj:4898)
	at cider.nrepl.middleware.slurp$normalize_content_type.invokeStatic(slurp.clj:46)
	at cider.nrepl.middleware.slurp$normalize_content_type.invoke(slurp.clj:41)
	at cider.nrepl.middleware.slurp$slurp_url_to_content_PLUS_body.invokeStatic(slurp.clj:95)
	at 

@Bost
Copy link

Bost commented Feb 19, 2020

I think one can easily reproduce this bug with:

$ lein new foo && cd foo
Generating a project called bar based on the 'default' template.
The default template is intended for library projects, not applications.
To see other templates (app, plugin, etc), try `lein help new`.
$ clojure -Sdeps '{:deps {nrepl {:mvn/version "0.6.0"} cider/cider-nrepl {:mvn/version "0.24.0"}}}' -m nrepl.cmdline --middleware '["cider.nrepl/cider-middleware"]'
nREPL server started on port 45013 on host localhost - nrepl://localhost:45013

Then in emacs after M-x cider-jack-in-clj

;; Connected to nREPL server - nrepl://localhost:34877
;; CIDER 0.24.0 (package: 20200215.223) (India), nREPL 0.6.0
;; Clojure 1.10.0, Java 11.0.6
;;     Docs: (doc function-name)
;;           (find-doc part-of-name)
;;   Source: (source function-name)
;;  Javadoc: (javadoc java-object-or-class)
;;     Exit: <C-c C-q>
;;  Results: Stored in vars *1, *2, *3, an exception in *e;
;; ======================================================================
;; [...]
;; ======================================================================
;;  Startup: /home/bost/bin/lein update-in :dependencies conj \[nrepl\ \"0.6.0\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.24.0\"\] -- repl :headless :host localhost
foo.core> (clojure.java.io/file "/tmp")
#object[java.io.File 0x378ca1 "/tmp"]ERROR: Unhandled REPL handler exception processing message {:op slurp, :url file:/tmp/, :session cbe12710-4cea-48cb-bd70-6e6fa7531cd8, :id 29}
java.io.IOException: Is a directory
	at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method)
	at java.base/sun.nio.ch.FileDispatcherImpl.read(FileDispatcherImpl.java:48)
	at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
	at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:245)
	at java.base/sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:223)
	at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
	at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
	at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
	at java.base/java.nio.file.Files.read(Files.java:3158)
	at java.base/java.nio.file.Files.readAllBytes(Files.java:3212)
	at cider.nrepl.middleware.slurp$slurp_url_to_content_PLUS_body.invokeStatic(slurp.clj:90)
	at cider.nrepl.middleware.slurp$slurp_url_to_content_PLUS_body.invoke(slurp.clj:82)
	at cider.nrepl.middleware.slurp$handle_slurp.invokeStatic(slurp.clj:116)
	at cider.nrepl.middleware.slurp$handle_slurp.invoke(slurp.clj:108)
	at clojure.lang.Var.invoke(Var.java:388)
	at cider.nrepl$wrap_slurp$fn__1586.invoke(nrepl.clj:95)
	at nrepl.middleware$wrap_conj_descriptor$fn__628.invoke(middleware.clj:16)
	at cider.nrepl$wrap_trace$fn__1734.invoke(nrepl.clj:426)
	at nrepl.middleware$wrap_conj_descriptor$fn__628.invoke(middleware.clj:16)
	at cider.nrepl$wrap_tracker$fn__1742.invoke(nrepl.clj:444)
	at nrepl.middleware$wrap_conj_descriptor$fn__628.invoke(middleware.clj:16)
	at nrepl.middleware.session$session$fn__1073.invoke(session.clj:272)
	at nrepl.middleware$wrap_conj_descriptor$fn__628.invoke(middleware.clj:16)
	at nrepl.server$handle_STAR_.invokeStatic(server.clj:18)
	at nrepl.server$handle_STAR_.invoke(server.clj:15)
	at nrepl.server$handle$fn__1110.invoke(server.clj:27)
	at clojure.core$binding_conveyor_fn$fn__5739.invoke(core.clj:2030)
	at clojure.lang.AFn.call(AFn.java:18)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

Whereby in "plain" clojure-repl it works:

$ clojure
Clojure 1.10.1
user=> (clojure.java.io/file "/tmp")
#object[java.io.File 0x1e287667 "/tmp"]
user=> 

@taylskid what about the patch you mentioned?

Thanks.

@dpsutton
Copy link
Contributor

I think this features should be off by default. Those who explicitly want images in the repl can work around these edge cases but exposing these rough edges to general users seems to give all the problems without any desire for the benefits.

@bbatsov
Copy link
Member

bbatsov commented Feb 19, 2020

I agree this should be off by default (that's on CIDER's end, though), but I also think we should try to fix the existing issues regardless.

@Bost
Copy link

Bost commented Feb 20, 2020

this features

??? feature?
That needs a little explanation. Merciii.

@bbatsov
Copy link
Member

bbatsov commented Feb 20, 2020

@Bost See https://docs.cider.mx/cider/repl/configuration.html#_displaying_images_in_the_repl

Basically the rich printing functionality is rough around the edges and causes issues like the one reported in this ticket. It's enabled by default, but we should probably disable it (at least until someone finds the time to polish it).

@Cartmanishere
Copy link
Contributor

This seems to be happening because of slurp middleware.

I think it can be fixed by adding a isDirectory check before reading the file contents in the slurp middleware.

What do you think? @bbatsov

@bbatsov
Copy link
Member

bbatsov commented Feb 29, 2020

This seems to be happening because of slurp middleware.

Yep.

I think it can be fixed by adding a isDirectory check before reading the file contents in the slurp middleware.

Yep, I think this is going to address the immediate issue.

@bbatsov
Copy link
Member

bbatsov commented Feb 29, 2020

There's also one NPE lurking in cider.nrepl.middleware.slurp/normalize_content_type, as indicated by the originally reported problem. I believe both fixes should be pretty straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants