cider
cider copied to clipboard
.nrepl-port (Permission denied) when starting a Clojure REPL in Cider without an associated file or Clojure project
When I cider-jack-in in Cider within a buffer that has no associated file or buffer, it starts a nrepl, but it seems nrepl is trying to create a .nrepl-port file somewhere, and whatever that default is, it doesn't have permissions to do so.
In my case, Clojure is installed here: /home/linuxbrew/.linuxbrew/bin/clojure, and I'm guessing this is where it was maybe trying to create a .nrepl-port?
I'd rather not give it permissions to that folder, is there a way to start a nrepl which doesn't need .nrepl-port or to have the .nrepl-port be written to the system temp folder?
{:clojure.main/message
"Execution error (FileNotFoundException) at java.io.FileOutputStream/open0 (FileOutputStream.java:-2).\n.nrepl-port (Permission denied)\n",
:clojure.main/triage
{:clojure.error/class java.io.FileNotFoundException,
:clojure.error/line -2,
:clojure.error/cause ".nrepl-port (Permission denied)",
:clojure.error/symbol java.io.FileOutputStream/open0,
:clojure.error/source "FileOutputStream.java",
:clojure.error/phase :execution},
:clojure.main/trace
{:via
[{:type java.io.FileNotFoundException,
:message ".nrepl-port (Permission denied)",
:at [java.io.FileOutputStream open0 "FileOutputStream.java" -2]}],
:trace
[[java.io.FileOutputStream open0 "FileOutputStream.java" -2]
[java.io.FileOutputStream open "FileOutputStream.java" 298]
[java.io.FileOutputStream <init> "FileOutputStream.java" 237]
[clojure.java.io$fn__11619 invokeStatic "io.clj" 230]
[clojure.java.io$fn__11619 invoke "io.clj" 230]
[clojure.java.io$fn__11543$G__11525__11550 invoke "io.clj" 69]
[clojure.java.io$fn__11593 invokeStatic "io.clj" 166]
[clojure.java.io$fn__11593 invoke "io.clj" 166]
[clojure.java.io$fn__11556$G__11521__11563 invoke "io.clj" 69]
[clojure.java.io$writer invokeStatic "io.clj" 119]
[clojure.java.io$writer doInvoke "io.clj" 104]
[clojure.lang.RestFn invoke "RestFn.java" 410]
[clojure.lang.AFn applyToHelper "AFn.java" 154]
[clojure.lang.RestFn applyTo "RestFn.java" 132]
[clojure.core$apply invokeStatic "core.clj" 669]
[clojure.core$spit invokeStatic "core.clj" 7021]
[clojure.core$spit doInvoke "core.clj" 7021]
[clojure.lang.RestFn invoke "RestFn.java" 425]
[nrepl.cmdline$save_port_file invokeStatic "cmdline.clj" 432]
[nrepl.cmdline$save_port_file invoke "cmdline.clj" 422]
[nrepl.cmdline$dispatch_commands invokeStatic "cmdline.clj" 458]
[nrepl.cmdline$dispatch_commands invoke "cmdline.clj" 447]
[nrepl.cmdline$_main invokeStatic "cmdline.clj" 470]
[nrepl.cmdline$_main doInvoke "cmdline.clj" 465]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.core$apply invokeStatic "core.clj" 667]
[clojure.main$main_opt invokeStatic "main.clj" 514]
[clojure.main$main_opt invoke "main.clj" 510]
[clojure.main$main invokeStatic "main.clj" 664]
[clojure.main$main doInvoke "main.clj" 616]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.main main "main.java" 40]],
:cause ".nrepl-port (Permission denied)"}}
What you propose is doable, but it will add a lot of complexity for a modest gain. I'll think about potential ways to improve this.
Actually, the issue was that, since I was starting Emacs in WSL2 with a windows shortcut, the working dir of Emacs was /mnt/c/Windows/System32 and the default-directory of the buffer was thus the same, and nRepl tries to create a .nrepl-port in the same folder as where Emacs is started in this case, as that's also the working dir the started nRepl process inherits from.
That folder requires root to write too, so there was a permission denied error.
I fixed it by making sure I start in Emacs in my home folder. Now it works.