Calling a webpage from repl and a debugger?

I am using luminus building a web application. I am getting type errors like

java.base/java.lang.Long cannot be cast to java.base/java.lang.String

but I can’t really find the error. My question is, is there any debugger available in clojure luminus? Like a simple step debugger (gdb etc)?
A for now I have to redirect my output to a test.html to view different variables.

and another question: How do I call a webpage from repl? that would also help a lot.

That “cannot be cast” error with the same class name seems like its reason is two different class loaders that were used to load the same class. Can’t really say anything else about it just given its description.
Update: seems like I need a break because I read the OP as if it was about casting Long to Long.

Regarding debugging - so far, I only have reasonable experience with Cursive, and it can debug Clojure code just fine. There are some peculiarities to it, but when you get used to it, it’ll become rather natural.

How do I call a webpage from repl?

What do you mean by “calling a webpage”? Executing a command that makes a browser window open at the provided URL? If so, then clojure.java.browse/browse-url.

That sounds like you’re trying to perform a String operation on a Long value. I’m not familiar with luminous, but doesn’t it give you a stack trace of the exception? It should be fairly simple to track from there.

what I meant was that I have a specific function defined in home,clj:

(defn par [{:keys [params]}]  
  (layout/render params "test.html" {:data params :data2 (keys params)})) ;; {:name (get-in req [:params :name] "noname")

(defn home-routes []
  [ "" 
   ;; {:middleware [middleware/wrap-csrf
   ;;               middleware/wrap-formats]}
   ["/" {:get home-page}]
   ["/about" {:get about-page}]
   ....
   ["/par" par]
    ...)

I can access this function from repl but I want to call if from a webrequest from repl, i.e with the routing and so on. Then I can examine req and see what is being passed to the function.

I’m not sure at what level you want to test this. I use Reitit, and routinely test my handlers with request maps that have the needed shape. I suspect you could do a similar thing in whatever stack you are using. Otherwise, you should look at your console output for that stack trace of your casting exception.

To me, it sounds this could be explored and fixed with a REPL. REPL-driven development isn’t very common, so there’s an official guide for it:

https://clojure.org/guides/repl/introduction

Perhaps worth having a look :slight_smile:

If you’re able to provide examples (here in this thread) that others can run in their own REPL, it’s also easier to help you! Everybody wins :grin:

As stated above, i want to call my function from repl that takes a request as an argument. The request is a dictionary with different key value pairs and I want to check these values. Normaly, you have an html page that sends these values through a router, and that router sends the request to a function. So the question is not really how to use the repl per se, it is how can I simulate a html call to my function in repl?
There is a similiar example in luminus where curl is used to call a function, but I want to do it from the repl. I hope this makes everything clear.

it’s actually pretty easy to debug this with clojure:

  1. In your handler function, bind it to a temporary variable.
(defn main-handler [req]
  (def *debug-request* req)
  .....)
  1. then generate a request (either from html or a http library) to capture the request.
  2. test the request against your handler:
(home-routes *debug-request*)

after you’ve figured out what’s wrong, delete the *debug-request* line.

1 Like

there’s also mocking libraries that can help as well:

ok, but the

(def debug-request req)

requires the req as an argument, and that one is not available in the repl, so the following error occur:

user=> (rental.routes.home/*debug-request*)
Execution error (ArityException) at user/eval24135 (form-init16465374154616516791.clj:1).
Wrong number of args (0) passed to: clojure.lang.PersistentHashMap

That’s not what’s happening. Now you’re trying to call a hash map as a function - not eval it.

Try:

rental.routes.home/*debug-request*

(no parens)

Edit - and thanks for posting REPL examples, that makes it WAY easier to help you!

1 Like

ah ok, no parens, now it is working. thanks

Perfect!

Happy to help - and good luck on the project!