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 output is not printed to repl #1588

Closed
whysoserious opened this issue Feb 25, 2016 · 19 comments · Fixed by clojure-emacs/cider-nrepl#387
Closed

stderr output is not printed to repl #1588

whysoserious opened this issue Feb 25, 2016 · 19 comments · Fixed by clojure-emacs/cider-nrepl#387
Labels

Comments

@whysoserious
Copy link
Contributor

Try running this code in cider repl:

user> (try
        (throw (Exception. "dupa"))
        (catch Exception e (println "this works")
               (.printStackTrace e)))
this works
;; => nil

Use the template below when reporting bugs. Please, make sure that
you're running the latest stable CIDER and that the problem you're reporting
hasn't been reported (and potentially fixed) already.

Steps to reproduce the problem

Run this code in cider repl:

(try
  (throw (Exception. "dupa"))
  (catch Exception e 
    (println "this works")
    (.printStackTrace e)))

Expected behavior

this works
STACKTRACE SHOULD BE PRINTED HERE
;; => nil

Actual behavior

this works
;; => nil

Environment & Version information

CIDER version information

; CIDER 0.10.2 (Java 1.8.0_25, Clojure 1.7.0, nREPL 0.2.12)

but it's also confirmed to fail in 0.11-SNAPSHOT

Emacs version

GNU Emacs 24.4.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21) of 2014-10-21 on builder10-9.porkrind.org

Operating system

MacOS 10.10.5
@bbatsov bbatsov added the bug label Feb 25, 2016
@bbatsov
Copy link
Member

bbatsov commented Feb 25, 2016

Excellent bug report! Thanks! :-)

@bbatsov
Copy link
Member

bbatsov commented Feb 25, 2016

So, it seems we forgot to handle stderr in our out middleware (https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/out.clj). Probably the stderr is ending up in the nrepl-server buffer.

@bbatsov bbatsov added this to the v0.11 milestone Feb 25, 2016
@Malabarba
Copy link
Member

Looking through that code now, I don't think I could have done a better job at making it specific to out. 😝

I wish I'd made it slightly more general.

@bbatsov
Copy link
Member

bbatsov commented Feb 26, 2016

You and me both. We definitely have to fix this before the release. If you don't have time I'll update it over the weekend (or at least I hope I'll have time for this).

@Malabarba
Copy link
Member

I'll have a bit of time sunday night.

@bbatsov
Copy link
Member

bbatsov commented Feb 26, 2016

OK, I'm leaving this to you then. :-)

@Malabarba
Copy link
Member

Actually, I just gave it a try over lunch and I don't know how to get it to work.

Redirecting #'*err* didn't have any effect for me.

Remember how we can redirect Clojure's *out* but not Java's stdout? I think this is the same problem, but with err.

@bbatsov
Copy link
Member

bbatsov commented Feb 29, 2016

Remember how we can redirect Clojure's out but not Java's stdout?

Actually I don't - aren't they the same thing? But I'm guessing even if this is true, it still makes sense to redirect *err* although it won't fix this particular problem.

@Malabarba
Copy link
Member

Actually I don't - aren't they the same thing?

Apparently not. To change Java's out we have to call setSystemOut, there's a comment about it on the code.

But I'm guessing even if this is true, it still makes sense to redirect *err* although it won't fix this particular problem.

Yes, but I failed to do that. :-P
Maybe I was just testing it wrong, but I couldn't get *err* to print on the REPL. For instance, no matter what I did, the following code would always print on the server buffer:

(binding [*out* *err*]
  (println "PRINT ME"))

@bbatsov
Copy link
Member

bbatsov commented Feb 29, 2016

Just generify the existing code and we'll take it from there. Baby steps. :-)

@Malabarba
Copy link
Member

See clojure-emacs/cider-nrepl#304

@bbatsov
Copy link
Member

bbatsov commented Feb 29, 2016

(binding out err)

P.S. This works fine for me.

image

@Malabarba
Copy link
Member

Yes. Because that's inside an Eval session. The point of this middleware is to redirect prints that happen on the server out (outside any Eval session).

@bbatsov
Copy link
Member

bbatsov commented Feb 29, 2016

I know. :-) Guess I misinterpreted your comment - I assumed err was misbehaving completely for you.

@Malabarba
Copy link
Member

Sorry, I was a little laconic. :-)
What I did was insert that code in one of cider's middleware functions, so it would get executed l on every request. And it was always printed on the server buffer.

@whysoserious
Copy link
Contributor Author

Probably the stderr is ending up in the nrepl-server buffer.

Confirmed:

java.lang.Exception: dupa
    at user$eval9887.invoke(form-init5480648096538554838.clj:51)
    at clojure.lang.Compiler.eval(Compiler.java:6782)
    at clojure.lang.Compiler.eval(Compiler.java:6745)
    at clojure.core$eval.invoke(core.clj:3081)
    at clojure.main$repl$read_eval_print__7099$fn__7102.invoke(main.clj:240)
    at clojure.main$repl$read_eval_print__7099.invoke(main.clj:240)
    at clojure.main$repl$fn__7108.invoke(main.clj:258)
    at clojure.main$repl.doInvoke(main.clj:258)
    at clojure.lang.RestFn.invoke(RestFn.java:1523)
    at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__634.invoke(interruptible_eval.clj:87)
    at clojure.lang.AFn.applyToHelper(AFn.java:152)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.core$apply.invoke(core.clj:630)
    at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1868)
    at clojure.lang.RestFn.invoke(RestFn.java:425)
    at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:85)
    at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__679$fn__682.invoke(interruptible_eval.clj:222)
    at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__674.invoke(interruptible_eval.clj:190)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

@holtzermann17
Copy link

Both *out* and *err* are getting directed to the *nrepl-server* buffer for me in the interaction with python -i' that I've described in the linked issue in the Conch queue.

@sjlnk
Copy link

sjlnk commented Aug 29, 2016

Using cider-connect all the output that is written to out or err from other than nrepl-threads output only to the server instance, not to the repl directly. This makes remote debugging really hard.

Also when running local repl (cider-jack-in) all the stack traces of uncaught exceptions are printed only on the nrepl-server buffer and not in repl buffer. I find this annoying.

@bhagany
Copy link
Contributor

bhagany commented Dec 29, 2016

This is closely related to #1896. I have a proof-of-concept fix here: https://github.com/bhagany/cider-nrepl/tree/repl-err. Hopefully it will soon be a PR. I'm currently stuck on the fact that the printed output gets printed before the prompt that causes it - that is, the prompt moves down and the output prints above it. If anyone has a solution to that, please let me know.

bhagany added a commit to bhagany/cider that referenced this issue Jan 2, 2017
bbatsov pushed a commit that referenced this issue Jan 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants