Skip to content
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

NullPointerException with getting started steps #218

Open
alza-bitz opened this issue Mar 12, 2025 · 8 comments
Open

NullPointerException with getting started steps #218

alza-bitz opened this issue Mar 12, 2025 · 8 comments

Comments

@alza-bitz
Copy link

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
Copy link
Author

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
Copy link
Author

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\"}}}"

@daslu
Copy link
Member

daslu commented Mar 12, 2025

Many thanks, @alza-bitz.

I will look soon.

@daslu
Copy link
Member

daslu commented Mar 12, 2025

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).

@behrica
Copy link
Member

behrica commented Mar 12, 2025

Probably duplication of #185

@daslu
Copy link
Member

daslu commented Mar 12, 2025

Thanks!

@alza-bitz
Copy link
Author

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 🙏

@daslu
Copy link
Member

daslu commented Mar 12, 2025

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants