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

Port arg is missing :parse-fn #201

Closed
stefan-toubia opened this issue Jun 30, 2020 · 5 comments
Closed

Port arg is missing :parse-fn #201

stefan-toubia opened this issue Jun 30, 2020 · 5 comments

Comments

@stefan-toubia
Copy link

Trying to start reply with a --port arg throws the following exception

ClassCastException java.lang.String cannot be cast to java.lang.Number
	nrepl.server/start-server/addr--1156 (server.clj:120)
	nrepl.server/start-server (server.clj:128)
	nrepl.server/start-server (server.clj:96)
	reply.eval-modes.nrepl/get-connection (nrepl.clj:158)
	reply.eval-modes.nrepl/get-connection (nrepl.clj:156)
	reply.eval-modes.nrepl/main (nrepl.clj:202)
	reply.eval-modes.nrepl/main (nrepl.clj:200)
	reply.main/launch-nrepl/fn--2391 (main.clj:79)
	clojure.core/with-redefs-fn (core.clj:7514)
	clojure.core/with-redefs-fn (core.clj:7498)
	reply.main/launch-nrepl (main.clj:78)
	reply.main/launch-nrepl (main.clj:72)

Looks like there needs to be a :parse-fn added to parse strings to int.

["--port" "Start new nREPL server on this port"]))

@trptcolin
Copy link
Owner

Which version of reply are you using? This was a bug fixed in 0.4.4 - details in #199

@stefan-toubia
Copy link
Author

Oh! I'm on 0.4.3, thanks!

While I have you here, I've been trying to work reply into my workflow with calva. Right now if I start a standalone nrepl, nrepl automatically chooses a port and exposes a port you can connect to, as well as making an .nrepl-port file.

nREPL server started on port 60959 on host localhost - nrepl://localhost:60959

I may have missed this but I did not see how to mimic this when using reply, is this supported?

@trptcolin
Copy link
Owner

Hmm, lein trampoline run does use nREPL by default, and picks a random port. And then lein trampoline run --attach PORT_NUMBER will let you attach to the same runtime.

I'm not sure there's currently a way to get that generated port number other than (a) doing the thing I did, where you lsof -nPi | grep java and find the exposed port, or (b) if you're in the runtime, looking at (:port @reply.eval-modes.nrepl/nrepl-server). Details:

(defn get-connection [{:keys [attach host port scheme]
:or {scheme "nrepl"}}]
(let [server (when-not attach
(nrepl.server/start-server
:port (when port
(-> port str Integer/parseInt))))
port (when-not attach
(:port server))
url (url-for attach host port scheme)]
(when server
(reset! nrepl-server server))
(when (-> url java.net.URI. .getScheme .toLowerCase #{"http" "https"})
(load-drawbridge))
(nrepl/url-connect url)))

I don't think I'd want us to write an .nrepl-port file explicitly, since that naming responsibility seems like it belongs all together wherever it lives (sounds like in the nREPL codebase), but I'm open to having some config where you could tell REPLy something like --write-port-file "path/to/file"? I'd defer to @bbatsov though.

@trptcolin
Copy link
Owner

I'm going to go ahead & close this issue - feel free to open another (or a PR!) if the above answer doesn't get you what you need for connecting to a port!

@stefan-toubia
Copy link
Author

Thanks again for the help!

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

No branches or pull requests

2 participants