clerk

teodorlu 2024-03-10T12:18:35.576849Z

Hi! Are there known Clerk issues with defprotocol, defrecord or “bare” namespaces? I’m hitting some errors, putting details in thread.

teodorlu 2024-03-10T12:19:13.221199Z

“bare” namespace: I’m using :paths ["."] and a Clojure file in the same directory as the deps.edn file.

teodorlu 2024-03-10T12:19:33.466329Z

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"

teodorlu 2024-03-10T12:19:55.726789Z

screenshot attached.

teodorlu 2024-03-10T12:20:58.542899Z

I’m unable to produce the same error by evaulating forms from the top to the bottom.

teodorlu 2024-03-10T12:21:40.125819Z

A call to clerk/clear-cache! and a following call to clerk/show! seems to fix the error.

teodorlu 2024-03-10T12:22:48.315099Z

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.

teodorlu 2024-03-10T12:24:19.322889Z

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)

teodorlu 2024-03-10T12:52:11.399419Z

Clerk version: io.github.nextjournal/clerk {:mvn/version "0.15.957"}

mkvlr 2024-03-10T12:52:18.816939Z

there’s https://github.com/nextjournal/clerk/issues/497 which could be related?

👀 1
teodorlu 2024-03-10T12:53:15.866619Z

Sounds related.

teodorlu 2024-03-10T12:53:38.435229Z

Want me to add the details i put in this thread into issue 497 as a comment?

mkvlr 2024-03-10T12:53:57.410649Z

yes please

👍 1
mkvlr 2024-03-10T12:55:58.488519Z

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

👍 1
mkvlr 2024-03-10T12:56:40.973039Z

might be good to spend some time to at least document the pitfalls here

👍 1
teodorlu 2024-03-10T12:58:30.107669Z

I would appreciate section in the book (or a doc somewhere else) on current limitations and (potential) workarounds a lot.

👍 2
teodorlu 2024-03-10T13:05:03.112299Z

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

🙏 1
Andrea 2024-03-12T10:53:14.104089Z

@teodorlu I’d also think the error you’re running into is closer to 455

👀 1
Andrea 2024-03-12T11:00:48.150189Z

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 analyzer

👀 1
Andrea 2024-03-12T11:16:03.350599Z

the same example clerk-shows fine if the protocol is defined in another ns, or if the namespaces is evaluated via REPL before

Andrea 2024-03-12T11:20:01.113179Z

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

Andrea 2024-03-12T11:25:16.567369Z

(I don’t think it does)

Andrea 2024-03-12T11:36:32.750789Z

maybe skipping form analysis altogether for nss marked no-cache might be desirable to circumvent these problems?

Andrea 2024-03-12T11:37:48.330969Z

@teodorlu in your case, a ns level no-cache prevents the error from showing up right?

teodorlu 2024-03-12T11:38:47.578429Z

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.

Andrea 2024-03-12T11:43:29.625069Z

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 setup

👀 1
phronmophobic 2024-03-12T18:28:32.453409Z

Adding {: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.

Andrea 2024-03-12T18:31:48.969819Z

yeah I can see them, maybe paste them in https://github.com/nextjournal/clerk/issues/455 thank you!

👍 1
phronmophobic 2024-03-11T18:33:28.765879Z

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"

👀 1