Hi! Are there known Clerk issues with defprotocol, defrecord or “bare” namespaces? I’m hitting some errors, putting details in thread.
“bare” namespace: I’m using :paths ["."] and a Clojure file in the same directory as the deps.edn file.
This is the error I’m getting:
:clojure.error/cause
"No implementation of method: :sample of protocol: #'second-dice/Sample found for class: second_dice.Dice"screenshot attached.
Full namespace, version that gives me the error: https://github.com/teodorlu/play.teod.eu/tree/fe70f7ed3fc6f997669b5356925f220d0c6e5038/how-much-is-that-second-dice-worth/second_dice.clj
I’m unable to produce the same error by evaulating forms from the top to the bottom.
A call to clerk/clear-cache! and a following call to clerk/show! seems to fix the error.
I tried to isolate the error, assuming it was just the defprotocol or the defrecord. But I haven’t been say exactly what is causing the error.
It seems to happen sometimes when I’m implementing my protocol for a new record.
I currently have the REPL state that gave me the error open, so I could possibly provide more data. (not sure what kind of data is relevant)
Clerk version: io.github.nextjournal/clerk {:mvn/version "0.15.957"}
there’s https://github.com/nextjournal/clerk/issues/497 which could be related?
Sounds related.
Want me to add the details i put in this thread into issue 497 as a comment?
yes please
not surprised this isn’t working well yet, we haven’t spent a lot of time on this and it does need quite a bit of special handling
might be good to spend some time to at least document the pitfalls here
I would appreciate section in the book (or a doc somewhere else) on current limitations and (potential) workarounds a lot.
added a comment to the issue:
https://github.com/nextjournal/clerk/issues/497#issuecomment-1987222271
I included the whole output from *cider-error*, which I didn’t paste into this thread (it’s big).
@teodorlu I’d also think the error you’re running into is closer to 455
now, I’m trying to narrow that down, but I seem to hit another issue even for a simpler repro:
;; # 🐞Protocol Issues
(ns scratch.protocol-issues
(:require [nextjournal.clerk :as clerk]))
(defprotocol P
(foo [this]))
(defrecord R []
P
(foo [_] "foo"))
(foo (R.))
(comment
;; reset in memory state
(run! (partial ns-unmap *ns*) (keys (ns-publics *ns*))))
this is over cursive nREPL, which might have some different ns setup altogether, but I get:
Unhandled java.lang.NullPointerException
Cannot read field "ns" because "sym" is null
:trace [[clojure.lang.Compiler maybeResolveIn "Compiler.java" 7424]
[clojure.core$ns_resolve invokeStatic "core.clj" 4366]
[clojure.core$resolve invokeStatic "core.clj" 4379]
[clojure.core$map$fn__5951 invoke "core.clj" 2770]
[clojure.lang.LazySeq sval "LazySeq.java" 44]
[clojure.lang.RT seq "RT.java" 535]
[clojure.core$seq__5483 invokeStatic "core.clj" 139]
[clojure.core$reduce1 invokeStatic "core.clj" 932]
[clojure.core$set invokeStatic "core.clj" 4120]
[clojure.core$emit_defrecord invokeStatic "core_deftype.clj" 149]
...
[nextjournal.clerk.analyzer$analyze_form$fn__57549 invoke "analyzer.clj" 136]
originating from clerk’s analyzerthe same example clerk-shows fine if the protocol is defined in another ns, or if the namespaces is evaluated via REPL before
@smith.adriane are protocols and implementations defined in the same ns as well? Does a {:nextjournal.clerk/no-cache true} in the ns metadata help circumvent your issue?
(I don’t think it does)
maybe skipping form analysis altogether for nss marked no-cache might be desirable to circumvent these problems?
@teodorlu in your case, a ns level no-cache prevents the error from showing up right?
can’t check right now, will get back to you later. If you want to test yourself, the full namespace with all source code is open, and there’s a link in the issue! I haven’t tested no-cache on ns yet.
I tried, unfortunately I can’t get past the
java.lang.NullPointerException
Cannot read field "ns" because "sym" is null
I mentioned above in my REPL setupAdding {:nextjournal.clerk/no-cache true} did not seem to help. Unfortunately, my setup isn't* minimal, but it can reliably reproduce the error. Not sure if you can see the logs at https://github.com/phronmophobic/llama.clj/actions/runs/8253925607/job/22576887992, but I can copy/paste them somewhere if that would help.
yeah I can see them, maybe paste them in https://github.com/nextjournal/clerk/issues/455 thank you!
Is this related https://github.com/nextjournal/clerk/issues/455 ? I also ran into a similar issue recently with an error like "No implementation of method: of protocol"