NullPointerException with getting started steps
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/
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)
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\"}}}"
Many thanks, @alza-bitz.
I will look soon.
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).
Probably duplication of #185
Thanks!
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 Many thanks for the helpful advice.
I'll leave the issue open so we can return to that when we have some time.