Fork me on GitHub
#shadow-cljs
<
2024-07-14
>
Joseph Graham08:07:01

What is the meaning of this error in the browser console? This is from a simple ClojureScript project that was working yesterday, but seems to be broken after rebooting my laptop. If I run on the terminal I see this:

~/Repos/blog-index$ npx shadow-cljs watch app
shadow-cljs - config: /home/joseph/Repos/blog-index/shadow-cljs.edn
shadow-cljs - socket connect failed, server process dead?
shadow-cljs - updating dependencies
shadow-cljs - dependencies updated
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.28.10 running at 
shadow-cljs - nREPL server started on port 44499
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
Exception in thread "async-dispatch-3" java.io.IOException: UT002002: Channel is closed
        at io.undertow.websockets.core.WebSocketChannel.send(WebSocketChannel.java:354)
        at io.undertow.websockets.core.WebSockets.sendBlockingInternal(WebSockets.java:992)
        at io.undertow.websockets.core.WebSockets.sendBlockingInternal(WebSockets.java:986)
        at io.undertow.websockets.core.WebSockets.sendTextBlocking(WebSockets.java:200)
        at shadow.undertow$fn$reify__17649$fn__17773$state_machine__6617__auto____17812$fn__17815.invoke(undertow.clj:490)
        at shadow.undertow$fn$reify__17649$fn__17773$state_machine__6617__auto____17812.invoke(undertow.clj:490)
        at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:978)
        at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:977)
        at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:982)
        at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:980)
        at shadow.undertow$fn$reify__17649$fn__17773.invoke(undertow.clj:490)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at clojure.core.async.impl.concurrent$counted_thread_factory$reify__484$fn__485.invoke(concurrent.clj:29)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.base/java.lang.Thread.run(Thread.java:840)
[:app] Build completed. (175 files, 0 compiled, 0 warnings, 2.83s)

thheller08:07:54

no clue. where are your source maps? I see NextJS in the trace?

Joseph Graham08:07:33

I don't have any source maps apparently:

Joseph Graham08:07:46

It gave those source map errors even when it worked though

Joseph Graham08:07:57

Perhaps I best just re-build my shadow project from scratch and copy+paste my code over

thheller08:07:26

unlikely that will change anything

thheller08:07:37

what is your build :target?

thheller08:07:54

seems like it might be using the incorrect :asset-path if :browser

Joseph Graham08:07:49

{:source-paths ["src/cljs"
                ;; "test/cljs"
                ]
 :dependencies [[cljs-http "0.1.48"]
                [reagent "1.2.0"]]
 :dev-http {3010 "resources/public/"}
 :builds {:app {:output-dir "resources/public/cljs/"
                :asset-path "."
                :target :browser
                :modules {:main {:init-fn blog-index.index/main!}}}
          ;; :test {:target :node-test
          ;;        :output-to "target/test.js"
          ;;        :ns-regexp "-test$"}
          }
 ;; :test {:runner :shadow.test-runner
 ;;        :build-id "test"}
 }

Joseph Graham08:07:33

I commented the test bits since they are the only things I can remember changing since the last time it worked

Joseph Graham09:07:33

ah OK I changed the asset path to cljs and I no-longer get the source map errors

Joseph Graham09:07:52

same error about cljs-runtime though

thheller09:07:01

well you now should know where your code fails? looks like you are supplying a wrong argument somewhere

thheller09:07:17

somewhere in blog-index.index

thheller09:07:15

this error happens when you call array-map/hash-map with an odd number of arguments

Joseph Graham09:07:36

ah OK for some reason I thought the errors were coming from cljs-runtime

thheller09:07:10

cljs-runtime is the folder where the debug files live, no meaning beyond that. they aren't even used and only exist there for source map purposes. if they are are used in any way thats a bug?

Joseph Graham09:07:26

right I was clicking on the link in the firefox debugger and it was showing me some code that wasn't mine so I assumed cljs-runtime was some code

Joseph Graham09:07:44

I am doing some stuff with array-map, just trying to understand what's wrong with it

(defn category-by-date
  "sort the categories by the post with the most recent date within that category"
  [cats]
  (let [;; this looks at a single category to find the most recent post
        get-biggest-post (fn [cat]
                           (apply max (map :date cat)))
        ;; this compares categories based on the most recent post from each
        comp (fn [a b]
               (> (get-biggest-post a) (get-biggest-post b)))

        ;; sort the categories
        cats-sorted (sort-by val comp cats)]

    ;; convert back to map
    (apply array-map cats-sorted)))

thheller09:07:27

can't use apply there

thheller09:07:41

use (into {} cats-sorted)

thheller09:07:10

do a (js/console.log cats-sorted) before that and look at the shape of the data

Joseph Graham09:07:13

ah right that works!

Joseph Graham09:07:17

OK I think that must be what I had yesterday but I swapped it out for array-map to ensure it would be ordered.

Joseph Graham09:07:10

ordinary map does seem to be ordered though, despite the fact that the docs claim it's not

thheller09:07:41

always treat maps as unordered. only happens to be a side-effect that array-map is ordered. maps by design are considered unordered

thheller09:07:05

if you want order use some of the other non cljs.core implementations, or better yet don't use a map at all. there are some libs for this, but can't remember their names.

Joseph Graham09:07:13

ah OK. I suppose it might not need to be a map as it's just gonna be converted to HTML

Joseph Graham09:07:40

thanks anyway. probably saved me an hour of confusing myself

Joseph Graham09:07:00

and it will teach me to commit to git more often