Fork me on GitHub
#shadow-cljs
<
2017-11-30
>
Jon08:11:39

tried requiring ["path" :as path] today, got huge error messages...

Jon08:11:50

not trying to reproduce yet..

Jon09:11:17

as I remembered it was like maximum call stack exceeded

Jon09:11:44

something like arrary-of caused.. didn't check it

thheller09:11:00

given that the shadow-cljs CLI script does this as well I’m quite confident it works. https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/npm/cli.cljs#L3

thheller09:11:27

unless you maybe tried to do it with :target :browser which won’t work because its a node only package

Jon09:11:34

will try to repro that later.

Jon09:11:48

it was :target :nodejs, I used fs module

Jon09:11:03

=>> node target/main.js
SHADOW import error /Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/shadow.module.main.append.js

/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs.core.js:11154
var self__ = this;
                                                                                             ^
RangeError: Maximum call stack size exceeded
    at Array.join (native)
    at cljs.core.Keyword.cljs$core$IPrintWithWriter$_pr_writer$arity$3 (/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs.core.js:11154:94)
    at Object.cljs$core$pr_writer_impl [as pr_writer_impl] (/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs.core.js:31863:12)
    at cljs$core$pr_writer (/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs/core.cljs:9739:6)
    at /Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs/core.cljs:9861:30
    at Object.cljs$core$pr_sequential_writer [as pr_sequential_writer] (/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs/core.cljs:9594:39)
    at Object.cljs$core$print_prefix_map [as print_prefix_map] (/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs.core.js:32481:18)
    at cljs$core$print_map (/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs/core.cljs:9871:8)
    at Object.cljs$core$pr_writer_impl [as pr_writer_impl] (/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs/core.cljs:9680:23)
    at cljs$core$pr_writer (/Users/chen/work/find-colors/target/shadow-cljs/builds/app/dev/out/cljs-runtime/cljs/core.cljs:9739:6)

Jon09:11:24

=>> cat src/server/main.cljs

(ns server.main
  (:require ["walk-sync" :as walk-sync]
            [clojure.string :as string]
            ["fs" :as fs]
            ["path" :as path])) ; <---

(defn main! []
  (println path) ; <---
  (let [base-dir js/process.env.base
        paths (filter
               (fn [filepath] (string/ends-with? filepath ".tsx"))
               (walk-sync base-dir))
        *colors (atom [])]
    (doseq [filepath paths]
      (let [content (fs/readFileSync (str base-dir filepath) "utf8")]
        (doseq [line (string/split-lines content)]
          (if (string/includes? line "#")
            (let [color (re-find (re-pattern "#[0-9a-f]{3,6}") line)]
              (if (some? color) (swap! *colors conj color) (println line)))))))
    (println (string/join "\n" (sort (set @*colors))))))

(defn reload! [] (main!))

thheller09:11:20

uhm why would you println that?

thheller09:11:32

its a recursive JS obj. don’t do that.

thheller09:11:48

(js/console.log path) should work since it detects circles

Jon09:11:39

at first I used a local variable called path and it broke the global path.. so I tried to print

thheller09:11:57

yeah its not safe to print (some) javascript objects

Jon09:11:12

any patterns to figure out recursive objects?

thheller09:11:33

just don’t print JS objects in general

thheller09:11:49

clojure print is for clojure objects not JS objects

Jon09:11:58

okay 😟

thheller09:11:59

it might work with some JS objects but it is not safe

thheller09:11:09

use js/console.log when in doubt

thheller09:11:49

[zilence@zpro ~]$ node
> require("path")
{ resolve: [Function: resolve],
  normalize: [Function: normalize],
  isAbsolute: [Function: isAbsolute],
  join: [Function: join],
  relative: [Function: relative],
  _makeLong: [Function: _makeLong],
  dirname: [Function: dirname],
  basename: [Function: basename],
  extname: [Function: extname],
  format: [Function: format],
  parse: [Function: parse],
  sep: '/',
  delimiter: ':',
  win32:
   { resolve: [Function: resolve],
     normalize: [Function: normalize],
     isAbsolute: [Function: isAbsolute],
     join: [Function: join],
     relative: [Function: relative],
     _makeLong: [Function: _makeLong],
     dirname: [Function: dirname],
     basename: [Function: basename],
     extname: [Function: extname],
     format: [Function: format],
     parse: [Function: parse],
     sep: '\\',
     delimiter: ';',
     win32: [Circular],
     posix: [Circular] },
  posix: [Circular] }

Jon09:11:11

well, Circular

thheller09:11:16

clojure will endlessly descend into the [Circular] things

thheller09:11:24

eventually blowing up the stack

Jon09:11:38

why don't println detect it's not Clojure data and print woth #js ...

Jon09:11:12

cljs.user=> (println (clj->js {:a 1}))
#js {:a 1}
nil
cljs.user=>

thheller09:11:22

it does that yeah … but it does not detect circles and stops .. it just keeps going

Jon09:11:24

so it still needs to format the data, which means traverse the structure again?

Jon09:11:47

well, have to accept that

thheller09:11:23

since you really have to go out of your way to create circular structures in clojure thats fine

thheller09:11:26

JS not so much

Jon09:11:16

just console.log is longer to write, I preferred println first

mitchelkuijpers11:11:29

While developing, we run into this exception a lot when a compile faills:

[:worker-error {:resources [[:shadow.build.classpath/resource "atlas_crm/ui/components/dialog.cljc"]], :shadow.cljs.devtools.server.system-bus/topic :shadow.cljs.devtools.server.system-msg/resource-update} java.lang.NoClassDefFoundError: Could not initialize class shadow.build.warnings$get_source_excerpts$iter__46278__46282$fn__46283$fn__46284$fn__46286]

thheller11:11:04

is that all? no more stack?

thheller11:11:04

there should be a logfile in target/shadow-cljs

thheller11:11:52

it should log a proper warning with complete stack. I removed the prn since thats not useful at all.

mitchelkuijpers11:11:08

Ah ok no it only gives us this in the repl

thheller11:11:52

no logfile?

mitchelkuijpers11:11:09

No logfile in target/shadow-cljs

thheller11:11:48

ah wait … you are using :lein. hmm do you have any kind of logging configured?

thheller11:11:56

and … I’m stupid … I set the logfile name to logging.properties so thats not good 😛

thheller11:11:18

anyways that does not apply when using lein

thheller12:11:26

when using lein it uses whatever logging setup you have configured

thheller12:11:12

that might be an issue if you have the slf4j-nop on the classpath, which means no logging at all.

mitchelkuijpers12:11:31

No I have logback on the classpath

thheller12:11:51

then it should have logged somewhere depending on the config you have

thheller12:11:13

unless you disable warnings

mitchelkuijpers12:11:08

I know what it is thnx

timovanderkamp12:11:46

17-11-30 12:21:13 UnknownHost WARN [shadow.cljs.devtools.server.util:286] - failed to handle server msg {:resources [[:shadow.build.classpath/resource atlas_crm/ui/components/dialog.cljc]], :shadow.cljs.devtools.server.system-bus/topic :shadow.cljs.devtools.server.system-msg/resource-update}
                                           java.lang.Thread.run              Thread.java:  748
             java.util.concurrent.ThreadPoolExecutor$Worker.run  ThreadPoolExecutor.java:  617
              java.util.concurrent.ThreadPoolExecutor.runWorker  ThreadPoolExecutor.java: 1142
                            java.util.concurrent.FutureTask.run          FutureTask.java:  266
                                                            ...                               
                                      clojure.core/bound-fn*/fn                 core.clj: 1995
                                             clojure.core/apply                 core.clj:  661
                                                            ...                               
                                    clojure.core/with-bindings*                 core.clj: 1965 (repeats 2 times)
                                             clojure.core/apply                 core.clj:  657
                                                            ...                               
shadow.build.compiler/par-compile-cljs-sources/fn/iter/fn/fn/fn             compiler.clj:  726
                          shadow.build.compiler/par-compile-one             compiler.clj:  667
               shadow.build.compiler/generate-output-for-source             compiler.clj:  621
                       shadow.build.compiler/maybe-compile-cljs             compiler.clj:  572
                    shadow.build.compiler/maybe-compile-cljs/fn             compiler.clj:  596
                       shadow.build.warnings/get-source-excerpt             warnings.clj:   55
                      shadow.build.warnings/get-source-excerpts             warnings.clj:   52
                                              clojure.core/into                 core.clj: 6815
                                            clojure.core/reduce                 core.clj: 6748
                                    clojure.core.protocols/fn/G            protocols.clj:   13
                                      clojure.core.protocols/fn            protocols.clj:   75
                              clojure.core.protocols/seq-reduce            protocols.clj:   24
                                               clojure.core/seq                 core.clj:  137
                                                            ...                               
              shadow.build.warnings/get-source-excerpts/iter/fn             warnings.clj:   41
           shadow.build.warnings/get-source-excerpts/iter/fn/fn             warnings.clj:   41
java.lang.NoClassDefFoundError: Could not initialize class shadow.build.warnings$get_source_excerpts$iter__46278__46282$fn__46283$fn__46284$fn__46286

mitchelkuijpers12:11:37

It gives us this in the logging, we do log warnings. I seems to fail on initializing some class

thheller12:11:09

thats super weird, not doing anything special there

thheller12:11:26

especially since it’s already supposed to catch all errors

thheller12:11:26

maybe lein has some old AOT cache? I really can’t see how line 41 can fail

thheller12:11:28

except that I may need to expand to Throwable

mitchelkuijpers12:11:07

It seems to break on a macro.. and also if we import the same thing twice by accident

thheller12:11:50

thats doesn’t explain NoClassDefFoundError though

thheller12:11:58

try [email protected]. only change is that it now catches Throwable since NoClassDefFoundError is not an exception

timovanderkamp13:11:05

I tried that version and this is the result:

Exception in thread "async-dispatch-2" 
java.lang.ExceptionInInitializerError
	at shadow.cljs.devtools.errors$user_friendly_error.invokeStatic(errors.clj:253)
	at shadow.cljs.devtools.errors$user_friendly_error.invoke(errors.clj:253)
	at shadow.cljs.devtools.server.util$print_build_failure.invokeStatic(util.clj:61)
	at shadow.cljs.devtools.server.util$print_build_failure.invoke(util.clj:59)
	at shadow.cljs.devtools.server.util$print_worker_out.invokeStatic(util.clj:79)
	at shadow.cljs.devtools.server.util$print_worker_out.invoke(util.clj:63)
	at shadow.cljs.devtools.server.util$stdout_dump$fn__49338$state_machine__7021__auto____49343$fn__49346.invoke(util.clj:119)
	at shadow.cljs.devtools.server.util$stdout_dump$fn__49338$state_machine__7021__auto____49343.invoke(util.clj:119)
	at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:973)
	at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:972)
	at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:977)
	at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:975)
	at clojure.core.async.impl.ioc_macros$take_BANG_$fn__7039.invoke(ioc_macros.clj:986)
	at clojure.core.async.impl.channels.ManyToManyChannel$fn__1082$fn__1083.invoke(channels.clj:95)
	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:748)
Caused by: java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace
	at clojure.lang.Compiler.currentNS(Compiler.java:7397)
	at clojure.lang.LispReader$EvalReader.invoke(LispReader.java:1310)
	at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:843)
	at clojure.lang.LispReader.read(LispReader.java:275)
	at clojure.lang.LispReader.read(LispReader.java:206)
	at clojure.lang.LispReader.read(LispReader.java:195)
	at clojure.lang.RT.readString(RT.java:1871)
	at clojure.lang.RT.readString(RT.java:1866)
	at shadow.cljs.devtools.errors$user_friendly_error$fn__49243.<clinit>(errors.clj:254)

thheller13:11:25

I really have no idea whats going on there

thheller13:11:36

nowhere in that file to I call read-string

thheller13:11:25

just in case did you try running lein clean?

timovanderkamp13:11:57

I will try it again, just to be sure

thheller13:11:10

I think I found a thing, you are running in nREPL correct?

thheller13:11:31

[email protected] at least fixes the java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace

timovanderkamp13:11:01

Yes I do, alright I will try that version out

timovanderkamp14:11:53

This is what i get with version 2.0.111

Exception in thread "async-dispatch-8" 
java.lang.ExceptionInInitializerError
	at shadow.cljs.devtools.errors$user_friendly_error.invokeStatic(errors.clj:254)
	at shadow.cljs.devtools.errors$user_friendly_error.invoke(errors.clj:253)
	at shadow.cljs.devtools.server.util$print_build_failure.invokeStatic(util.clj:61)
	at shadow.cljs.devtools.server.util$print_build_failure.invoke(util.clj:59)
	at shadow.cljs.devtools.server.util$print_worker_out.invokeStatic(util.clj:79)
	at shadow.cljs.devtools.server.util$print_worker_out.invoke(util.clj:63)
	at shadow.cljs.devtools.server.util$stdout_dump$fn__49342$state_machine__7021__auto____49347$fn__49350.invoke(util.clj:119)
	at shadow.cljs.devtools.server.util$stdout_dump$fn__49342$state_machine__7021__auto____49347.invoke(util.clj:119)
	at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:973)
	at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:972)
	at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:977)
	at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:975)
	at clojure.core.async.impl.ioc_macros$take_BANG_$fn__7039.invoke(ioc_macros.clj:986)
	at clojure.core.async.impl.channels.ManyToManyChannel$fn__1082$fn__1083.invoke(channels.clj:95)
	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:748)
Caused by: java.lang.RuntimeException: Can't resolve find-ns
	at clojure.lang.Util.runtimeException(Util.java:221)
	at clojure.lang.LispReader$EvalReader.invoke(LispReader.java:1315)
	at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:843)
	at clojure.lang.LispReader.read(LispReader.java:275)
	at clojure.lang.LispReader.read(LispReader.java:206)
	at clojure.lang.LispReader.read(LispReader.java:195)
	at clojure.lang.RT.readString(RT.java:1871)
	at clojure.lang.RT.readString(RT.java:1866)
	at shadow.cljs.devtools.errors$user_friendly_error$fn__49246.<clinit>(errors.clj:254)

thheller14:11:42

I don’t get whats going on .. seriously this doesn’t make any sense to me.

thheller14:11:43

but the *ns* binding seems to be the cause since I changed that and the error changed

thheller14:11:07

try [email protected]. I removed that binding completely, maybe nrepl just doesn’t like doing that.

timovanderkamp14:11:03

Thanks a lot @thheller, works perfectly!

jgdavey14:11:26

I’m puzzling through an issue: Using shadow-cljs cljs-repl :id outputs response as I’d expect, but within Emacs/cider, after connecting and running (shadow.cljs.devtools.api/nrepl-select :id-of-build), responses come back, but they are always a string.

jgdavey14:11:08

Any clue where I should look for this, @thheller? I’m happy to work on it

jgdavey14:11:41

cljs.user> (+ 1 2)
"3"

thheller14:11:46

we already struggled with this once I really don’t know what I’m supposed to do

thheller14:11:57

it is the cider nREPL middleware causing this

jgdavey14:11:11

Hmm, interesting

jgdavey14:11:55

Does manually specifiying middleware in shadow-cljs.edn override the default stack?

thheller14:11:49

no it just adds

thheller14:11:04

(:value response) is a string

thheller14:11:09

but that for some reason gets pprint’d

jgdavey14:11:35

I’ll play around with it. Didn’t realize you’d already done the same. I’ll let you know if I come up with anything. Thanks!

thheller14:11:08

the problem is that cursive is fine with what I’m doing

thheller14:11:24

cider isn’t

jgdavey14:11:37

You mean with the piggieback emulation?

thheller14:11:53

no that doesn’t seem to be the issue

thheller14:11:02

when I remove the cider middleware everything is fine in cursive

thheller14:11:16

when I add it cursive also prints escaped strings

thheller14:11:53

since it works without the cider middleware I thought I was doing it correctly

thheller14:11:00

but that does not seem to be true

thheller14:11:50

its really hard to find documentation for what this should actually do

jgdavey14:11:24

Totally. Cider’s a big project

thheller14:11:38

I think that was the print code

thheller14:11:54

either way .. I guess I’ll need to read-string the result I get back from the CLJS repl

thheller14:11:14

which seems super silly given that it will just be printed again

jgdavey14:11:13

Yeah, but that code you linked me to does call (read-string) conditionally

jgdavey14:11:28

Must be on the other side of the if there

jgdavey16:11:32

Okay, so actually issuing a pprint eval (in Emacs C-c C-p) rather than a vanilla eval behaves as expected, reading the string

thheller18:11:04

I can just read-string the value I get from the client if all else fails