Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start cider debug session by a http request ? #1170

Closed
jinwei233 opened this issue Jun 26, 2015 · 22 comments
Closed

start cider debug session by a http request ? #1170

jinwei233 opened this issue Jun 26, 2015 · 22 comments

Comments

@jinwei233
Copy link

the new 0.9.x debug feature is cool !

M-x cider-debug-defun-at-point , eval a function in a emacs buffer, then a debug session started

but in a web dev workflow , a function is invoked by a http request , I enter a url in the browser and a handler then excuted , so my question is : is there a way to debug handler function in this kind of situation?

@jinwei233 jinwei233 changed the title invoke debug session in web dev workflow start debug session in web dev workflow Jun 26, 2015
@jinwei233 jinwei233 changed the title start debug session in web dev workflow start cider debug session by a http request ? Jun 26, 2015
@Malabarba
Copy link
Member

Thanks for filing this. Could you detail how that web deve workflow is setup? I'm not familiar with it.
I mean things like what cider command do you use to start/connect the repl. If you know implementation details that would help too.

@bbatsov
Copy link
Member

bbatsov commented Jun 27, 2015

I'm guess the question can be rephrased like this - "How can you debug a function that you don't invoke directly in CIDER?" (in this case the browser would invoke the function as the result of some callback). I think there's something special that needs to be done, as long as you've connected to a process in which the function in question has been instrumented.

@jinwei233
Copy link
Author

as @bbatsov said

debug a function that you don't invoke directly in CIDER

give a similar example, use geben to debug PHP function sayHello . when refresh url in browser, the debug session invoked

  • M-x geben set up a debug server
  • M-x geben-set-break-line add a break point
  • refresh browser , then a debug session started

debugger_optimized

@bbatsov
Copy link
Member

bbatsov commented Jul 9, 2015

@Malabarba Did you check if this is working on not? If not, I guess you need just a simple compojure app.

@Malabarba
Copy link
Member

@bbatsov
No, I haven't tried this yet. The debugger has kept me pretty busy so far.

I'm guess the question can be rephrased like this - "How can you debug a function that you don't invoke directly in CIDER?" (in this case the browser would invoke the function as the result of some callback).

I could be wrong here, but the way the debugger is designed it should always trigger when the function is executed, no matter how that happens. Although there are a couple aspects of it which might not work without an eval message, the breakpoints should still trigger.

This tells me that either (a) the function is not getting instrumented properly, or (b) the system in question support something we do (which is a pretty wide umbrella).

@Malabarba
Copy link
Member

@WeweTom Just to be sure, this is Clojure, right? Not ClojureScript?

@bbatsov bbatsov closed this as completed Aug 9, 2015
@bbatsov
Copy link
Member

bbatsov commented Aug 9, 2015

Closing due to lack of recent activity.

@Malabarba
Copy link
Member

FWIW, it's probably fixed. I've been using clojure for webdev and I made a fix to the debugger for it.

@jinwei233
Copy link
Author

Sorry for my late reply.
I updated my cider to CIDER 0.10.0snapshot (package: 20150810.1008) , It still does not work as I expected .
@Malabarba what version do you use ? and how do you debug your code ?

I want to debug json-items , after cider-debug-defun-at-point , I visit url /api/items in my browser , but nothing happens.

image

@Malabarba
Copy link
Member

@WeweTom I'm on the same version as you. Did you ensure that the cider-nrepl version is also the snapshot?

In my webdev workflow, I used cider-jack-in to start the repl, then called a ring-jetty function to start the server (which was made of compojure routes).
Then, I could debug my handler functions by typing C-u C-M-x and then visiting the respecting page on the browser.

What was your workflow like?
Maybe you could create a minimal Github repo which I can use to reproduce the problem?

@jinwei233
Copy link
Author

@Malabarba
my cider-nrepl version is nREPL 0.2.10 , where to find the snapshot version ?
and I created a repo at https://github.com/WeweTom/clj-cider-debug-demo

@Malabarba
Copy link
Member

@WeweTom That's your cloure.tools.nrepl version. What do you get if you evaluate cider.nrepl.version/version in the repl?

@jinwei233
Copy link
Author

@Malabarba wow , after change ~/.lein/profiles.clj [cider/cider-nrepl "0.9.1"] to [cider/cider-nrepl "0.10.0-SNAPSHOT"] , it works now ! thanks Malabarba !

{:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]]
 :user {:plugins [[lein-localrepo "0.5.3"]
                  [cider/cider-nrepl "0.10.0-SNAPSHOT"]]
        :dependencies [[org.clojure/tools.nrepl "0.2.10"]]}}

@jinwei233
Copy link
Author

after play with it for just a few minute , I find a problem . I begin a debug session A, after that , I refresh url in browser , Session A is destroyed , and begin a new session . so , can you change this behavior : when there is an active session , new sessions are ignored . or it would be great to add a debug flag in http request . only http request with certain flag , debug session will be invoked. just like PHP geben debug tool I priviously posted , geben has a chrome plugin to add a http header XDEBUG_SESSION_START , alternately , this flag can be in url like http://localhost:8000/items?CIDER_DEBUG_START .

thanks for your great work.

@Malabarba
Copy link
Member

Relying on a flag wouldn’t make a lot of sense right now. The debugger is purely expression based, and has no knowledge of the environment in which it's being run.

Still, I'd like to handle better the situation of overlapping sessions, so I'll look into that.

@NicolasPetton
Copy link
Contributor

@Malabarba this fix alone is worth a release IMHO. The debugger is useless for web development (at least for me) in 0.9.1.

@Malabarba
Copy link
Member

@NicolasPetton Hang tight. 0.10 is really close now. :-)

@bbatsov
Copy link
Member

bbatsov commented Oct 30, 2015

Is it? :-)

On Friday, 30 October 2015, Artur Malabarba notifications@github.com
wrote:

@NicolasPetton https://github.com/NicolasPetton Hang tight. 0.10 is
really close now. :-)


Reply to this email directly or view it on GitHub
#1170 (comment)
.

Best Regards,
Bozhidar Batsov

http://www.batsov.com

@Malabarba
Copy link
Member

Well, the date on the milestone is close. Whether we'll meet that is another matter. :-)

@seanirby
Copy link

seanirby commented Mar 6, 2016

I'm using CIDER 0.11.0 and the debugger does indeed trigger on an http request as expected. However, the eval feature is broken for me. I'm going to poke around at it for an hour or two to see whats going on but I figured I would chime in here first.

I notice that upon entering an instrumented function that the current namespace *ns* is equal to clojure.core rather than the namespace declared by the source file.

@seanirby
Copy link

seanirby commented Mar 6, 2016

The error happens whenever I confirm an expression by pressing RET. Heres the stack trace:


java.lang.IllegalStateException: Can't change/establish root binding of: *ns* with set
    at clojure.lang.Var.set(Var.java:221)
    at clojure.lang.RT$1.invoke(RT.java:241)
    at cider.nrepl.middleware.debug$eval_with_locals.invokeStatic(debug.clj:227)
    at cider.nrepl.middleware.debug$eval_with_locals.invoke(debug.clj:207)
    at cider.nrepl.middleware.debug$read_debug_eval_expression.invokeStatic(debug.clj:235)
    at cider.nrepl.middleware.debug$read_debug_eval_expression.invoke(debug.clj:229)
    at cider.nrepl.middleware.debug$read_debug_command.invokeStatic(debug.clj:306)
    at cider.nrepl.middleware.debug$read_debug_command.invoke(debug.clj:266)
    at todo.core$der$fn__12609$fn__12610.invoke(server.clj:41)
    at todo.core$der$fn__12609.invoke(server.clj:41)
    at todo.core$der.invokeStatic(server.clj:41)
    at todo.core$der.invoke(server.clj:40)
    at clojure.lang.Var.invoke(Var.java:379)
    at ring.adapter.jetty$proxy_handler$fn__3322.invoke(jetty.clj:24)
    at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:497)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)

@Malabarba
Copy link
Member

Ok, this is probably because we try to restore the namespace after evaluating. I'll try to look into a proper solution later, but for now I'll patch this with a try/catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants