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

stderr not sent back to client #28

Closed
tzzh opened this issue Oct 2, 2020 · 6 comments
Closed

stderr not sent back to client #28

tzzh opened this issue Oct 2, 2020 · 6 comments

Comments

@tzzh
Copy link
Contributor

tzzh commented Oct 2, 2020

When running bb --nrepl-server and the connecting to it with a nrpel client for examplelein repl :connect 1667, stderr is not visible in the client, for example the following doesn't print anything

user=> (binding [*out* *err*]
    #_=>   (println "Hello, STDERR!"))
nil
@borkdude
Copy link
Contributor

borkdude commented Oct 2, 2020

Hey @tzzh, thanks for the issue. We have tests for normal output here:

https://github.com/babashka/babashka.nrepl/blob/master/test/babashka/nrepl/server_test.clj#L213-L230

It should not be too hard to support the same for :err probably.

@tzzh
Copy link
Contributor Author

tzzh commented Oct 8, 2020

Hey, so I realised when running this code that sci/err is not bound but I am not sure how to bind out the right writer.
Basically I am getting

#error {
 :cause class sci.impl.vars.SciUnbound cannot be cast to class java.io.Writer (sci.impl.vars.SciUnbound is in unnamed module of loader 'app'; java.io.Writer is in module java.base of loader 'bootstrap')
 :via
 [{:type clojure.lang.ExceptionInfo
   :message class sci.impl.vars.SciUnbound cannot be cast to class java.io.Writer (sci.impl.vars.SciUnbound is in unnamed module of loader 'app'; java.io.Writer is in module java.base of loader 'bootstrap') [at line 1, column 1]
   :data {:type :sci/error, :line 1, :column 1, :message class sci.impl.vars.SciUnbound cannot be cast to class java.io.Writer (sci.impl.vars.SciUnbound is in unnamed module of loader 'app'; java.io.Writer is in module java.base of loader 'bootstrap') [at line 1, column 1]}

so then in

(let [result (sci/with-bindings {sci/out pw}
(eval-form ctx form))]

I am not sure how to get the right print writer I tried sci/err pw but then it sends stderr to stdout and I am not sure how I can bind sci/err to the right writer

@borkdude
Copy link
Contributor

borkdude commented Oct 8, 2020

@tzzh I think you need to build another replying-print-writer that sends "err" messages instead of "out" messages:

;; from https://github.com/nrepl/nrepl/blob/1cc9baae631703c184894559a2232275dc50dff6/src/clojure/nrepl/middleware/print.clj#L99

and bind that to sci/err.

I think it's nicer to make "out" and "err" pluggable as an argument.
Note that the original nREPL also does this:

https://github.com/nrepl/nrepl/blob/1cc9baae631703c184894559a2232275dc50dff6/src/clojure/nrepl/middleware/print.clj#L115

@tzzh
Copy link
Contributor Author

tzzh commented Oct 8, 2020

OK cool I am not super familiar with the nrepl code but I am starting to understand thanks 👍 - I'll try and make a PR for this

@borkdude
Copy link
Contributor

borkdude commented Oct 8, 2020

@tzzh The pod protocol was largely inspired by nREPL so you're probably more familiar than you realize :).

@borkdude
Copy link
Contributor

borkdude commented Oct 8, 2020

Thanks!

@borkdude borkdude closed this as completed Oct 8, 2020
borkdude added a commit to babashka/babashka that referenced this issue Oct 8, 2020
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