This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-11
Channels
- # announcements (16)
- # architecture (1)
- # babashka (24)
- # beginners (49)
- # biff (5)
- # calva (13)
- # clerk (3)
- # clj-kondo (4)
- # clojure (46)
- # clojure-dev (1)
- # clojure-europe (22)
- # clojure-losangeles (5)
- # clojure-nl (1)
- # clojure-norway (15)
- # clojure-uk (2)
- # clojurescript (28)
- # code-reviews (2)
- # community-development (6)
- # conjure (10)
- # cursive (8)
- # datalevin (15)
- # datomic (32)
- # events (1)
- # fulcro (9)
- # hyperfiddle (32)
- # introduce-yourself (1)
- # lsp (27)
- # malli (1)
- # matrix (3)
- # missionary (6)
- # off-topic (24)
- # practicalli (2)
- # rdf (1)
- # re-frame (7)
- # reagent (10)
- # reitit (5)
- # rewrite-clj (9)
- # sci (6)
- # scittle (4)
- # shadow-cljs (23)
- # tools-deps (74)
- # vim (19)
- # xtdb (5)
I'm having a problem in a ring app and it's totally new to me. I had middleware working which would inject :current-user into every request object. All of the sudden I intermittently had certain endpoints returning 403's with the message "you must be logged in" The endpoints are consistent for different endpoint/user combinations. I looked into it and noticed by swap!'ing a debug variable that my handlers are being called twice in the instance of the 403's and only once in the 200's. These are the only clues I could generate about my current bug, what else should I be looking for?
e.g. an endpoint like /current-user
, the handler could be called twice per network request
Maybe it's your browser that duplicates the requests? CORS os favicon.ico? I think it's worth checking the network tab in your browser and check what and who emits those extra requests.
(def cusess-handlers
["/current-user-sessions" {:get {:handler (fn [r]
(swap! dbggg conj r)
(response {:ok true})
;;(get-current-user-sessions-handler r)
)}
:swagger {:tags ["sessions"]}}])
In this instance, I can see there's one (swap! dbggg conj r)
per request... i.e. the @dbgggg atom increments by one request every request on the endpoint
But then if I flip to
{:handler (fn [r]
(swap! dbggg conj r)
;;(response {:ok true})
(get-current-user-sessions-handler r)
)}
I can see the endpoint is getting hit twice!Maybe there is something in your router or middleware that performs the request twice.
> In the network tab, I see just one request Browsers don't show some requests in there. The most robust way to determine it is to read your server's logs or use Wireshark.
Also, in case you're using Reitit there's a debug route transformer - it will print out request and response information before and after every middleware, including a colorful diff.
Thanks. I zero'd in on there not being a second network request. I found the unhandled exception and I don't know why, it's calling the handler to be called a second time.
What middleware do you have? Easy to imagine for it to be something a tad weird like
(try
(handle (wrap request))
(catch Exception _
(handle request)))
Have you checked what goes on in the session middleware? Does it receive a cookie and match it to a session?
Oh, sounds like the 403 has been resolved. Nvm
Is this in emacs? I'm pretty sure the cljr- functions for thread and unwind are obsolete and simply alias the clojure- functions
always use clojure mode functions over cljr, as they don't require compiling. I'm a bit biased as my cljr almost never works
Hi everyone! I’m trying to make an existing Java class implement Seqable
. I’ve looked into using extend-type
, but it seems that this only allows me to implement protocols, not interfaces. Does anyone have any suggestions for how I can achieve this?
You can't extend an existing (compiled) Java class to implement a Java interface. You might be able to: • Change that class in the source code so it extends that interface via regular Java means • Create a new class that inherits the existing one and implements the interface • Create a new class that delegates to the existing one and implements the interface
Unfortunately, I am working with an external library Java class, so I cannot modify its source code to extend the interface directly. Creating a new class that inherits or delegates to the existing one is also not an option for me. Do you know if there’s a protocol I could use instead to work around this problem?
If you can't wrap instances of the existing class in anything at all, then I believe you're out of luck because the seq
function can only be applied to the following things:
• Implementers of one of these interfaces Seqable
, Iterable
, CharSequence
, Map
• Subclasses of the ASeq
class
• Instances of the LazySeq
class
• null
• Arrays
If you can create a wrapper in Clojure, then you can simply use reify
, just like the iteration
function does.
Wrappers are not out of the question. In fact, I have considered creating a protocol that “mimics” the Java class and using reify
to implement the protocol and Seqable
interface. However, I’m curious if there’s a simpler or more straightforward way to achieve this.
hrm, what’s the pattern for accessing a static field on a Java interface? I guess I somehow haven’t run into this before
e.g. (Integer/MAX_VALUE)
oh! my bad!
then you need to figure out why the static init is broken and fix that other wise the jvm won't load the class file and you can't read fields
there may be some way to read static fields from a class without running its static init, but for data types that cannot be serialized directly in byte code, those values need to be constructed and then set as the fields value, which is done in the static init
kind of late but you can also add breakpoints to interface static initializers with intelliJ and then fire the load from the repl, maybe that helps debugging those kind of issues