-
Notifications
You must be signed in to change notification settings - Fork 14
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
Spy logging interferes with compiled JS in CLJS #24
Comments
@mrrodriguez I suspect this only happens when cold-compiling a codebase that already has spy statements in it, can you confirm? |
@vvvvalvalval If I add a
So either way, it won't work with a lein + figwheel setup. My
and using Figwheel
The NPE from the analyzer is pretty hard to troubleshoot. I tried for a few hours one day and failed. I have to figure out how to recreate it with the Figwheel REPL analyzer pass and then walk through that. If I'm in a Figwheel CLJS (via piggieback) REPL, I have tried (require 'sc.api)
;;= nil
sc.api/spy
;;= #object[sc$api$spy] Both of those work. However, if I then do (sc.api/spy :foo)
;; throws an error
---- Could not Analyze <cljs form> line:1 column:1 ----
at line 1 <cljs repl>
1 (sc.api/spy :foo)
^---
---- Analysis Error ----
nil Interestingly I can do: (#'sc.api/spy nil nil :foo)
;;= returns the macroexpanded form I'm not sure if the NPE problem, analysis error, and the problem with the logger printing to the same out stream as the cljs compiler are all related. All of these issues have been hard to troubleshoot so far. This is actually happening to me in 2 separate CLJS projects too, so it isn't just something completely unique to one codebase. However, the lein + figwheel stack is the same. I've tried different recent versions of figwheel, and that doesn't change anything. I've read the relevant chunks of the |
I am also having this same issue, with the same figwheel and lein versions that @mrrodriguez is using. |
Any progress on this? Debugging the analyzer is a bit beyond my abilities, but happy to help with evidence collection etc. |
@nickstares yes I'd need a precise repro to make progress please - a minimal project reproducing the problem with the exact dependencies would be ideal. |
@vvvvalvalval I may try to get a reproducing case again today. I've had a hard time doing so before. When I make a small, dummy project, with a bunch of the same core dev dependencies, it hasn't happened. I have 2 "real" separate projects though, where it happens the same in each. I've been completely unable to use |
I can reproduce this using figwheel template. Once the app is up and running with cider and figwheel, All I have to do is add I do notice that this doesn't happen when using only See more info below. I created the project with: project.clj(defproject scope-capture-demo "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:min-lein-version "2.7.1"
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.10.238"]
[org.clojure/core.async "0.4.474"]]
:plugins [[lein-figwheel "0.5.16"]
[lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]]
:source-paths ["src"]
:cljsbuild {:builds
[{:id "dev"
:source-paths ["src"]
:figwheel {:on-jsload "scope-capture-demo.core/on-js-reload"
:open-urls ["http://localhost:3449/index.html"]}
:compiler {:main scope-capture-demo.core
:asset-path "js/compiled/out"
:output-to "resources/public/js/compiled/scope_capture_demo.js"
:output-dir "resources/public/js/compiled/out"
:source-map-timestamp true
:preloads [devtools.preload]}}
{:id "min"
:source-paths ["src"]
:compiler {:output-to "resources/public/js/compiled/scope_capture_demo.js"
:main scope-capture-demo.core
:optimizations :advanced
:pretty-print false}}]}
:figwheel {:css-dirs ["resources/public/css"]}
:profiles {:dev {:dependencies [[binaryage/devtools "0.9.9"]
[figwheel-sidecar "0.5.16"]
[cider/piggieback "0.3.1"]]
:source-paths ["src" "dev"]
:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}
;; need to add the compliled assets to the :clean-targets
:clean-targets ^{:protect false} ["resources/public/js/compiled"
:target-path]}}) core.cljs:(ns scope-capture-demo.core)
(require 'sci.api)
(defonce app-state (atom {:text "Hello world!"}))
(defn on-js-reload []
(sc.api/spy)
(prn @app-state)) profiles.clj:{:user {:dependencies [[vvvvalvalval/scope-capture "0.3.1"]]
:injections [(require 'sc.api)]}}
stacktrace:
|
@vvvvalvalval @nickstares I was able to recreate it in a similar way and agree that the problem only seems to be with the
EDIT: I looked a bit more at this and now I'm actually suspicious of
Looking at the relevant Cider code: (defn print-stream
"Returns a PrintStream suitable for binding as java.lang.System/out
or java.lang.System/err. All operations are forwarded to all output
bindings in the sessions of messages.
type is either :out or :err."
[type]
(let [printer (case type
:out '*out*
:err '*err*)]
(PrintStream. (proxy [OutputStream] []
(close [] (.flush ^OutputStream this))
(write
([int-or-bytes]
(.write @(resolve printer)
(if (instance? Integer int-or-bytes)
int-or-bytes
(String. int-or-bytes))))
([bytes ^Integer off ^Integer len]
(let [byte-range (byte-array
(take len (drop off bytes)))]
(.write @(resolve printer) (String. byte-range))))) <--- ERROR HAPPENS HERE
(flush []
(.flush @(resolve printer))))
true))) It looks like the call to EDIT (2): I played around with this and I'm now convinced the So the function A workaround for this issue is to put something like this: (sc.api.logging/register-cs-logger
:sc.api.logging/log-spy-cs
(fn [cs]
nil)) NOTE: This is really the same workaround (in concept) that was around prior to In your With this, there is no initial code site details logged anywhere. However, when execution points are logged later, they are logged at runtime to the CLJS out stream you'd expect, so you can still find where the execution points are to effectively use So now the question is, could/should |
The cljs compiler uses |
I still get logger output interleaved with the JS output that was discussed in #1
when using
[vvvvalvalval/scope-capture "0.2.0"]
in ClojureScript with Leiningen/cljs-build/figwheel setup.This problem seems to come and go from project to project or release to release of
scope-capture
for me. I haven't been able to narrow it down to a basic new project to reproduce it. I think it may be something with the combination of the tools involved.I'll add that I used to be able to use
scope-capture
with this same setup around the 2nd release. I am not sure I have enough details to be actionable here. I'm curious if anyone else is facing similar.The text was updated successfully, but these errors were encountered: