Fork me on GitHub
#cider
<
2021-02-18
>
bozhidar08:02:34

There's a cider-connected-hook.

bozhidar08:02:12

There's also cider-repl-init-code.

bozhidar08:02:56

(defvar cider-repl-require-repl-utils-code
  '((clj . "(clojure.core/apply clojure.core/require clojure.main/repl-requires)")
    (cljs . "(require '[cljs.repl :refer [apropos dir doc find-doc print-doc pst source]])")))

(defcustom cider-repl-init-code (list (cdr (assoc 'clj cider-repl-require-repl-utils-code)))
  "Clojure code to evaluate when starting a REPL.
Will be evaluated with bindings for set!-able vars in place."
  :type '(list string)
  :group 'cider-repl
  :package-version '(cider . "0.21.0"))

danielneal12:02:20

Is there a way of adding a breakpoint that will be hit when e.g. an http request is made, i.e. when a function is called indirectly rather than directly

jumar14:02:24

There should be no difference and your "breakpoint" should be triggered. That said, I often times get into a state where no breakpoints are activated for some reason - restarting the REPL typically helps.

danielneal14:02:57

hmm interesting. Is there more to it than doing cider-debug-defun-at-point in the function you want to debug, and then exercising the endpoint that calls the function?

jumar14:02:39

I think that's it: Of course you can also use #dbg which can be convenient if you have a larger function or if you want to break only on a specific condition: https://docs.cider.mx/cider/debugging/debugger.html#conditional-breakpoints

danielneal14:02:22

Do I need extra middleware apart from cider.nrepl/cider-middleware?

jumar14:02:46

No, I don't think so.

danielneal14:02:06

thanks, I'll keep at it

danielneal14:02:43

oh, it's working

danielneal14:02:50

restarting the repl worked

jumar15:02:47

Yeah, that's a PITA. I don't know why it sometimes happen but I hit this issue every now and then.

danielneal15:02:27

thanks for your help 🙂

bozhidar07:02:26

Guess you found some weird bug - probably the state of the debugger gets corrupted by something, otherwise I can't imagine the need for a restart.

jumar10:02:06

Is there a way to “debug” such debugger issues 😀?

rickmoynihan11:02:48

I stopped using the debugger years ago because the debugger was so temperamental debugging http requests.

danielneal09:02:58

I think the debugger stops working after I quit the debugger with q after debugging an http request. I got this error: Execution error (NullPointerException) at cider.nrepl.middleware.debug/abort! (debug.clj:143), and then the debugger wouldn't start up again when debugging the same function and request.

jumar09:02:29

Interesting observation - I didn't make a connection between these two things and I use q every now and then. I'll try to reproduce this in my project...

jumar09:02:10

@U051H1KL1 you're right! It would be worth to report this - I'd love to see this fixed.

rickmoynihan09:02:56

@U051H1KL1 IIRC now you mention it that sounds suspiciously similar to what I witnessed a few years back too — I thought I’d reported it, but it was maybe just on the slack channel and not in a ticket.

jumar09:02:05

It calls Thread's .stop method which is known to cause problems - maybe that't the issue? https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/debug.clj#L143

jumar09:02:16

Maybe a workaround is to press C to skip all the breakpoints? https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/debug.clj#L364 ... Oh no, that doesn't work either - so just c?

danielneal09:02:57

Yeah, c works for me

danielneal09:02:34

Interestingly, when debugging a function that is called indirectly via http, q doesn't appear on the list of options, and when pressed breaks the debugger going forward. When debugging a function called directly, q does appear on the list of functions, and when pressed, does not break the debugger.

👍 3
jumar10:02:42

Another thing that seems to mess up the debugger state is t (trace)

bozhidar08:02:35

> Is there a way to “debug” such debugger issues

bozhidar08:02:05

Same as with all other issues - monitoring the message exchange, instrumenting thing on the Elisp side and playing with the Clojure part of the debugger in the REPL.

bozhidar08:02:00

If someone wants to see this fixed any time soon they'll have to look into the problem themselves. As I've mentioned a few times - effectively no one but me is working on all the CIDER/nREPL related stuff these days, which means progress is slow and painful (if any).

bozhidar08:02:23

This is the most detailed overview of the internals of the debugger for those interested - https://drive.google.com/file/d/1YhnPBJOXbUzXfVOEojICFTwhCt_3u6Ss/view?usp=sharing

bozhidar08:02:35

(it's simpler than most people would think it is)

jumar11:02:20

Cool, thanks for sharing! I'll have a look next week if this is something I could do.

Eamonn Sullivan21:02:49

Am I doing something wrong here? I want to use an http mocking library in my tests, but I obviously don't need this in the production version of the library, so I added the dependency (clj-wiremock) like this:

{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.2"}
        clj-http/clj-http {:mvn/version "3.11.0"}
        org.clojure/data.json {:mvn/version "1.0.0"}}
 :aliases
 {:test {:extra-paths ["test"]
         :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}
                      kelveden/clj-wiremock {:mvn/version "1.5.7"}}}
but I can't eval the buffer on a test file in CIDER (C-c C-k). It does work if I move clj-wiremock to the :deps section. Is that right, or am I just missing something silly? I might be misunderstanding what the :test alias is for...

dpsutton21:02:35

did you add the test alias when jacking in?

Eamonn Sullivan21:02:55

Ah, do I have to do that? How do I do that?

dpsutton21:02:19

easiest way, hit C-u before jacking in and add a -A:test right after the bin/.../clojure part

Eamonn Sullivan21:02:21

Right, thanks! I've gone this long without ever needing a test-only dependency...

dpsutton21:02:18

no worries. if you update to the latest version of CIDER i can walk you through some dir-locals stuff to make sure you are always using the test alias so you never have to worry if you remembered to add it or not. it'll always be there when using CIDER

👀 3
Max Deineko21:02:18

Anything one should look at beside (cider-clojure-cli-global-options . "-M:test") ?

dpsutton21:02:05

i think that's correct. there was a little bit of flux and a clojure-cli-aliases or something like that recently

dpsutton21:02:26

still needs to be documented and its still missing a way to pass things at the end of the string to supply ports and such. ( i think)

Max Deineko21:02:09

ah, I see -- good to know!

Eamonn Sullivan21:02:12

Thanks. I probably am using the latest (I use straight.el), but other half is yelling at me to get off the computer. Will look this up... And that did work, btw. Thank you again!

danielneal09:02:58

I think the debugger stops working after I quit the debugger with q after debugging an http request. I got this error: Execution error (NullPointerException) at cider.nrepl.middleware.debug/abort! (debug.clj:143), and then the debugger wouldn't start up again when debugging the same function and request.