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

boot.util/auto-flush's PrintWriter doesn't handle offset and len parameters, which breaks cider #298

Closed
schmir opened this issue Sep 29, 2015 · 5 comments
Assignees
Labels

Comments

@schmir
Copy link
Contributor

schmir commented Sep 29, 2015

I'm using boot together with cider and get the following error when
trying to serve a web page.

The problem here seems to be that the PrintWriter generated in
boot.util/auto-flush does not handle the .write call [1] with offset and
len as additional parameters.

cider-nrepl also creates a custom PrintWriter object. However, they
implement a Writer proxy and wrap that in a PrintWriter [2]. Maybe
boot should do the same.

[1] http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html
[2] https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/out.clj#L43

Here's the stacktrace:

clojure.lang.ArityException: Wrong number of args (4) passed to: util/auto-flush/fn--1148
    at clojure.lang.AFn.throwArity(AFn.java:429)
    at clojure.lang.AFn.invoke(AFn.java:44)
    at boot.util.proxy$java.io.PrintWriter$ff19274a.write(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93)
    at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
    at cider.nrepl.middleware.out$fork_out$fn__20871.invoke(out.clj:51)
    at cider.nrepl.middleware.out.proxy$java.io.Writer$ff19274a.write(Unknown Source)
    at java.io.PrintWriter.write(PrintWriter.java:456)
    at java.io.PrintWriter.write(PrintWriter.java:473)
    at clojure.core$fn__5853.invoke(core_print.clj:199)
    at clojure.lang.MultiFn.invoke(MultiFn.java:233)
    at clojure.core$pr_on.invoke(core.clj:3548)
    at clojure.core$pr.invoke(core.clj:3560)
    at clojure.lang.AFn.applyToHelper(AFn.java:154)
    at clojure.lang.RestFn.applyTo(RestFn.java:132)
    at clojure.core$apply.invoke(core.clj:630)
    at clojure.core$prn.doInvoke(core.clj:3593)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:630)
    at clojure.core$println.doInvoke(core.clj:3613)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at taoensso.timbre.appenders.core$println_appender$fn__13414.invoke(core.clj:101)
    at taoensso.timbre$log1_fn$fn__13579.invoke(timbre.clj:407)
    at clojure.lang.PersistentArrayMap.kvreduce(PersistentArrayMap.java:373)
    at clojure.core$fn__6715.invoke(core.clj:6541)
    at clojure.core.protocols$fn__6531$G__6526__6540.invoke(protocols.clj:174)
    at clojure.core$reduce_kv.invoke(core.clj:6562)
    at taoensso.timbre$log1_fn.invoke(timbre.clj:364)
    at steinmetz.http.core$log_error$fn__41312.invoke(core.clj:755)
    at cemerick.friend$handler_request.invoke(friend.clj:222)
    at cemerick.friend$authenticate_STAR_.invoke(friend.clj:249)
    at cemerick.friend$authenticate$fn__32448.invoke(friend.clj:260)
    at user$fresh_app.invoke(user.clj:49)
    at ring.middleware.reload$wrap_reload$fn__31513.invoke(reload.clj:22)
    at org.httpkit.server.HttpHandler.run(RingHandler.java:91)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    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)

And here's the patch I'm using currently, which fixes the issue. I'm
not sure though how to handle stripping of ansi escape characters when
len and offset are passed to write:

diff --git a/boot/pod/src/boot/util.clj b/boot/pod/src/boot/util.clj
index 050bc53..e05457a 100644
--- a/boot/pod/src/boot/util.clj
+++ b/boot/pod/src/boot/util.clj
@@ -174,9 +174,12 @@
   (let [strip? #(and (not @*colorize?*) (string? %))
         strip  #(fn [s] (if (strip? s) (ansi/strip-ansi s) s))]
       (proxy [java.io.PrintWriter] [writer]
-      (write [s]
-        (.write writer ((strip) s))
-        (.flush writer)))))
+      (write
+        ([s off len]
+         (.write writer s off len))
+        ([s]
+         (.write writer ((strip) s))
+         (.flush writer))))))

 (defn extract-ids
   [sym]
@schmir schmir added the Bug label Sep 29, 2015
@kgxsz
Copy link

kgxsz commented Oct 12, 2015

I'm also seeing this.

@antonyshchenko
Copy link

I'm having the same issue

@antonyshchenko
Copy link

Thanks @schmir, your patch helped!

@dluksza
Copy link

dluksza commented Oct 18, 2015

I'm having the same issue with boot and timbre, when ever something is logged got the same stactrace.

Any change for this being fixed in next release?

@schmir schmir self-assigned this Oct 19, 2015
@schmir schmir closed this as completed in 5fbea77 Oct 19, 2015
@micha
Copy link
Contributor

micha commented Oct 24, 2015

Thanks @schmir! 🍻

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

No branches or pull requests

5 participants