nextjournal/clerk

Beginning v0.12.699, "serve!" no longer works in some platforms

Closed this issue · 5 comments

Beginning release v0.12.699 (it works up until v0.11.603), clerk is not able to serve pages in my platform (openjdk 17 on top of a corporate wsl running debian), raising the following exception when evaluating (clerk/serve! {:browse true :watch-paths ["src"]}):

1. Unhandled java.lang.UnsupportedOperationException
   The BROWSE action is not supported on the current platform!

              Desktop.java:  381  java.awt.Desktop/checkActionSupport
              Desktop.java:  531  java.awt.Desktop/browse
NativeMethodAccessorImpl.java:   -2  jdk.internal.reflect.NativeMethodAccessorImpl/invoke0
NativeMethodAccessorImpl.java:   77  jdk.internal.reflect.NativeMethodAccessorImpl/invoke
DelegatingMethodAccessorImpl.java:   43  jdk.internal.reflect.DelegatingMethodAccessorImpl/invoke
               Method.java:  568  java.lang.reflect.Method/invoke
            Reflector.java:  167  clojure.lang.Reflector/invokeMatchingMethod
            Reflector.java:  102  clojure.lang.Reflector/invokeInstanceMethod
                browse.clj:   54  clojure.java.browse/open-url-in-browser
                browse.clj:   76  clojure.java.browse/browse-url
                browse.clj:   68  clojure.java.browse/browse-url
                 clerk.clj:  399  nextjournal.clerk/serve!
                 clerk.clj:  362  nextjournal.clerk/serve!
                      REPL:   15  arithploration.core/eval28841
                      REPL:   15  arithploration.core/eval28841
             Compiler.java: 7570  clojure.lang.Compiler/eval
             Compiler.java: 7525  clojure.lang.Compiler/eval
                  core.clj: 3229  clojure.core/eval
                  core.clj: 3225  clojure.core/eval
    interruptible_eval.clj:  102  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 1990  clojure.core/with-bindings*
                  core.clj: 1990  clojure.core/with-bindings*
               RestFn.java:  428  clojure.lang.RestFn/invoke
    interruptible_eval.clj:  102  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  459  clojure.main/repl/fn
                  main.clj:  459  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1526  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   99  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   71  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  166  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  236  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  235  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  840  java.lang.Thread/run

Upon quick investigation, it seems that the fact that the browser can't be launched raises the exception and breaks the serve workflow. Although this is not directly related to clerk (see openmole/openmole#140 for example), this should be avoidable at the clerk level, as serving the pages should be independent from the convenience of launching a new window...

mk commented

Hi @AlexAti, thanks for the report. Are you sure it's related to a change in Clerk rather than a change in the JVM version?

I'm not seeing anything related to this in the diff, see v0.11.603...v0.12.699.

You can also try confirming that clojure.java.browse/browse-url does not work on your system by running the following:

clj -M -e "((requiring-resolve 'clojure.java.browse/browse-url) \"https://clerk.vision\")"

Are you suggesting you think it would be better to fail silently if the browser does can't be opened? I think that might also lead to surprising behavior…

Hi @mk! Thanks for your work!

I required an old version of clerk that worked, and I spotted this after just upgrading the version in my deps.edn; afterwards I just did some manual binary search until I found the version that breaks it, so not sure about whether its clerk's code or dependencies, but it triggers just by jumping from v0.11.603.

My quick guess is that this should have always happened, but it was silently failing due the "coerge" typo that was fixed here.

Running the code you provided me also triggers the same error:

$ clj -M -e "((requiring-resolve 'clojure.java.browse/browse-url) \"https://clerk.vision\")"
Execution error (UnsupportedOperationException) at java.awt.Desktop/checkActionSupport (Desktop.java:381).
The BROWSE action is not supported on the current platform!

Full report at:
/tmp/clojure-174686366672381146.edn

As to whether to warn about the error or halt the attempt to serve files, it can be argued both ways! But to me launching the browser is an extra on top of the main intent (to serve files), and that way it would be more robust. Alternatively I'd strengthen the error message of the exception to advise to remove ":browse true".

mk commented

But to me launching the browser is an extra on top of the main intent (to serve files), and that way it would be more robust.

@AlexAti agreed and implemented catching the exception in the commit above. Let me know if you think that's alright or feel free to open a PR with further suggestions.

I have the same issue: "BROWSE action is not supported" and Localhost not started.

Clojure 1.11.1
(clerk/serve! {:browse true})
Clerk webserver started on http://localhost:7777 ...
Execution error (UnsupportedOperationException) at java.awt.Desktop/checkActionSupport (Desktop.java:381).
The BROWSE action is not supported on the current platform!

I use Windows11 with WSL2 (Ubuntu 22.04.3 LTS) and Java Version:

openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment (build 17.0.11+9-Ubuntu-122.04.1)
OpenJDK 64-Bit Server VM (build 17.0.11+9-Ubuntu-122.04.1, mixed mode, sharing)

The same Notebook was working yesterday, but now it is not working.

How can I solve this issue?

Jens

changing deps.epn from

 :deps {
    org.clojure/clojure {:mvn/version "1.11.1"}
    io.github.nextjournal/clerk {:mvn/version "0.16.1016"}
  } 

to:

:deps {
    org.clojure/clojure {:mvn/version "1.11.1"}
    io.github.nextjournal/clerk {:mvn/version "0.11.603"}
  } 

solves the problem, but that is not a longterm solution.

Jens