clay icon indicating copy to clipboard operation
clay copied to clipboard

NullPointerException with getting started steps

Open alza-bitz opened this issue 9 months ago • 8 comments

Hi there,

I'm getting a NullPointerException when trying to follow the "getting started" steps here: https://scicloj.github.io/clay/#getting-started

This is in a VSCode dev container with Java 17, running from a directory with no deps.edn or Clojure project, so the classpath is just clay and transitive deps (I presume):

vscode@6755557927fb:/workspaces$ clj -Sdeps "{:deps {org.scicloj/clay {:mvn/version \"2-beta32\"}}}"
Clojure 1.12.0
(require '[scicloj.clay.v2.api :as clay])
nil
(clay/make! {:single-form '(+ 1 2 3)})
Clay serving at http://localhost:1972/
Wed Mar 12 10:51:44 UTC 2025 [http-kit-server-worker-1] ERROR - GET /
java.lang.NullPointerException: Cannot invoke "Object.toString()" because "s" is null
        at clojure.string$replace.invokeStatic(string.clj:101)
        at clojure.string$replace.invoke(string.clj:75)
        at scicloj.clay.v2.server$wrap_html.invokeStatic(server.clj:123)
        at scicloj.clay.v2.server$wrap_html.invoke(server.clj:121)
        at scicloj.clay.v2.server$routes.invokeStatic(server.clj:159)
        at scicloj.clay.v2.server$routes.invoke(server.clj:147)
        at clojure.lang.Var.invoke(Var.java:386)
        at org.httpkit.server$wrap_ring_websocket$ring_handler_STAR___1632.invoke(server.clj:437)
        at org.httpkit.server.HttpHandler.runSync(RingHandler.java:144)
        at org.httpkit.server.HttpHandler.run(RingHandler.java:138)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)
Execution error (IOException) at sun.net.www.protocol.http.HttpURLConnection/getInputStream0 (HttpURLConnection.java:2037).
Server returned HTTP response code: 500 for URL: http://localhost:1972/

alza-bitz avatar Mar 12 '25 10:03 alza-bitz

More info: I had to add the following packages to the dev container to get this far:

libxrender1, libxtst6, libxi6

Also, I get the same exception in a Calva REPL as well (if it helps to diagnose)

alza-bitz avatar Mar 12 '25 11:03 alza-bitz

Also, I get the same exception if I start a repl with noj instead of clay:

vscode@6755557927fb:/workspaces$ clj -Sdeps "{:deps {org.scicloj/noj {:mvn/version \"2-beta10.1\"}}}"

alza-bitz avatar Mar 12 '25 11:03 alza-bitz

Many thanks, @alza-bitz.

I will look soon.

daslu avatar Mar 12 '25 11:03 daslu

Hi @alza-bitz,

Could you create a clay.edn in your project root with the following content?

{:browser false}

This will prevent Clay from trying to automatically open the browser view. It seems it fails to do that from within the dev container.

Then, you will be able to open the URL yourself (and may need to take care of port forwarding, depending on your setup).

daslu avatar Mar 12 '25 11:03 daslu

Probably duplication of #185

behrica avatar Mar 12 '25 16:03 behrica

Thanks!

daslu avatar Mar 12 '25 17:03 daslu

Hi @alza-bitz, Could you create a clay.edn in your project root with the following content? {:browser false} This will prevent Clay from trying to automatically open the browser view. It seems it fails to do that from within the dev container. Then, you will be able to open the URL yourself (and may need to take care of port forwarding, depending on your setup).

Hi @daslu appreciate the quick response! I checked the docs here https://scicloj.github.io/clay/#configuration and with {:browse false} the exception goes away and the server starts. I then manually created a mapping for port 1971 and the UI is accessible at http://localhost:1971. Nice! 🙌

One suggestion I had based on experiences with other server apps running in dev containers, it seems that it's possible to detect this case on the server side by some rule, avoiding exceptions thrown and then the VS Code auto port mapping can work as expected.

I'm not sure how this would be done (some judicious exception handling when trying to open a browser perhaps), but in theory this would avoid the need for a config setting and the manual port mapping, saving two steps.

Thanks 🙏

alza-bitz avatar Mar 12 '25 18:03 alza-bitz

@alza-bitz Many thanks for the helpful advice.

I'll leave the issue open so we can return to that when we have some time.

daslu avatar Mar 12 '25 19:03 daslu