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

Unable to resolve var: cider.nrepl.middleware.trace/wrap-trace #96

Closed
ghost opened this issue Jul 21, 2014 · 21 comments
Closed

Unable to resolve var: cider.nrepl.middleware.trace/wrap-trace #96

ghost opened this issue Jul 21, 2014 · 21 comments

Comments

@ghost
Copy link

ghost commented Jul 21, 2014

Hi there,

As of last Friday myself and a couple others on my team have been experiencing this issue with cider-nrepl. Is this a known issue? I get the following stacktrace if I try to start a repl:

Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: cider.nrepl.middleware.trace/wrap-trace in this context, compiling:(/private/var/folders/gx/q3y1xf6x60s78zlp1g249blr0000gn/T/form-init2361553506959370289.clj:1:6479)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6651)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.analyze(Compiler.java:6406)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3719)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.analyze(Compiler.java:6406)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3719)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.access$100(Compiler.java:38)
at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6050)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.analyze(Compiler.java:6406)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5217)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3846)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6642)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.eval(Compiler.java:6700)
at clojure.lang.Compiler.eval(Compiler.java:6693)
at clojure.lang.Compiler.load(Compiler.java:7130)
at clojure.lang.Compiler.loadFile(Compiler.java:7086)
at clojure.main$load_script.invoke(main.clj:274)
at clojure.main$init_opt.invoke(main.clj:279)
at clojure.main$initialize.invoke(main.clj:307)
at clojure.main$null_opt.invoke(main.clj:342)
at clojure.main$main.doInvoke(main.clj:420)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve var: cider.nrepl.middleware.trace/wrap-trace in this context
at clojure.lang.Util.runtimeException(Util.java:221)
at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:659)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
... 33 more
REPL server launch timed out.

This is while including cider with the following in our profiles.clj: [cider/cider-nrepl "0.7.0-SNAPSHOT"]

Thanks,
Tom

@bbatsov
Copy link
Member

bbatsov commented Jul 24, 2014

Haven't run into this. Likely something is misconfigured, can't think of anything else that would result in a middleware var going AWOL.

@semperos
Copy link

As of today also seeing this. No config changes on my side.

@semperos
Copy link

I deleted my ~/.m2/repository/cider/cider-nrepl folder and did a lein clean on the project in question, which cleared this up.

@bbatsov
Copy link
Member

bbatsov commented Aug 8, 2014

Closing this as unreproducible.

@bbatsov bbatsov closed this as completed Aug 8, 2014
@malcolmsparks
Copy link

I got the same issue. The cause was that cider.nrepl.middleware.trace uses a var (trace/traced?) of org.clojure/tools.trace that was introduced since tools.trace-0.7.3. Any libraries in your project that depend on 0.7.3 (or earlier) of tools.trace may cause a version conflict. In my case, I was using a version of Liberator (0.11.x) that depended on tools.trace 0.7.3 (the latest version of Liberator, 0.12.x, appears to have fixed this).

It's always a good idea to be aware of any library version conflicts in your project's dependency tree. The way to view this is with

lein deps :tree

In my case, I set a global exclusion in my project such that none of my dependencies would bring in a (potentially different) version of tools.trace :-

:exclusions [org.clojure/tools.trace]

This is not a bug in cider-nrepl, but users upgrading to Cider 0.7.0 should be aware of the new requirement that their Clojure projects' dependencies must 'peacefully co-exist' with those brought into Clojure's app classloader by cider/cider-nrepl. Again, it's a good idea to check with lein deps :tree to ensure you know about any conflicts that exist.

@bbatsov
Copy link
Member

bbatsov commented Aug 12, 2014

@malcolmsparks You're spot on. We eventually made the same discovery while investigating a tools.namespace related bug.

I was a bit surprised that people actually use such tooling libraries in their projects - seems to me that they belong mostly in the realm of development tools. Anyways, we'll try to keep the number of cider dependencies to the bare minimum to avoid such nasty scenarios.

@benedekfazekas
Copy link
Member

an other way to solve this is how eastwood does it: see dependency readme. what do you guys think? is that an overkill? makes sense? cc @malcolmsparks

@bbatsov
Copy link
Member

bbatsov commented Aug 14, 2014

I definitely feel this is an overkill. Of course, it's also regrettable that a tool like eastwood needs be a project dependency - if it were me doing it, I probably would have made it standalone.

@benedekfazekas
Copy link
Member

well, it is basically a lein plugin which makes sense I guess. so you add it as a dependency/plugin in dev scope. and it does need the project's dependencies otherwise it is quite difficult to build a meaningful AST for the project namespaces if I understand it right...

@bbatsov
Copy link
Member

bbatsov commented Aug 14, 2014

and it does need the project's dependencies otherwise it is quite difficult to build a meaningful AST for the project namespaces if I understand it right...

You only need the source code to be build an AST.
A static analyzer should not care about a project's dependencies (I should know as I wrote one of the popular static analyzers for Ruby) - it's called static for a reason and the reason it only analyzes the AST (generally in the context of a single file), without regard for library details.

@benedekfazekas
Copy link
Member

I hear you and I am sure you are right. but then clojure.tools.analyzer and clojure.tools.analyzer.jvm is not a static analyzer in that sense (used by eastwood) I assume. In fact eastwood analyze+eval your code when linting it.

I also had a chat with Nicola the other day where he said:

At the moment there's no good way to get a meaningful AST out of a whole
namespace without evaluating each clojure form as you go, since anything
could happen at macroexpansion time, var interning, dynamic class
generation, local bindings injection etc. and I honestly doubt there
will ever be, this is a limitation imposed by the semantics of clojure
itself.

@bbatsov
Copy link
Member

bbatsov commented Aug 14, 2014

Ah, yes. Nicola's quite right, of course. I didn't consider any of those things when I wrote my previous comment.

@benedekfazekas
Copy link
Member

so back to the original question, the above said: do you still see this as an overkill for dev tools like cider-nrepl eastwood, refactor-nrepl etc?

@malcolmsparks
Copy link

A couple of years back I tried (and failed) to write a tool like Eastwood to detect redundant ns decls, if you do any significant re-factoring on a Clojure project you end up with lots of these. I didn't realise at the time the difficulty of doing this statically when you have a macro system, so concur with @benedekfazekas.

Looking at the current deps tree of cider-nrepl, I'm inclined to anticipate further issues like this one being posted by users, necessitating an FAQ or dedicated blog article to help steer around them. This depends on various factors such as how stable the libraries are, the extent to which cider-nrepl uses new features in them and scope-expansion bringing in more dependencies.

These issues may be mitigated if cider-nrepl keeps current with the tools libraries it depends on. Projects that depend on newer versions of these libraries may be doing so because they need new functionality, and so clashes with cider-nrepl will be common if cider-nrepl stagnates. But here's the rub: developers don't like forever updating their core development environment. "If it works, don't fix it" is the mantra here (especially if you code for a living). So I think, on balance, the approach taken by Eastwood is worth future consideration.

@benedekfazekas
Copy link
Member

probably this is a bit offtopic now, but working on refactor-nrepl and facing similar problems I was thinking if I should go the same way as Eastwood perhaps generalising the solution as a leiningen plugin or such. would be interested in your opinion specially @bbatsov and @malcolmsparks

@malcolmsparks
Copy link

IIRC, Eclipse does a similar thing by prefixing its embedded tools (e.g.
Jetty) with org.eclipse. Any ns renames would have to be tested, because a
library might make assumptions as to its namespaces. The lein plugin would
be useful, because this renaming process would have to be repeated on every
update of a library dependency. Renaming namespaces feels like a bit of a
hack, but I can't think of another viable approach.

On 14 August 2014 13:30, benedekfazekas notifications@github.com wrote:

probably this is a bit offtopic now, but working on refactor-nrepl and
facing similar problems I was thinking if I should go the same way as
Eastwood perhaps generalising the solution as a leiningen plugin or such.
would be interested in your opinion specially @bbatsov
https://github.com/bbatsov and @malcolmsparks
https://github.com/malcolmsparks


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

@bbatsov
Copy link
Member

bbatsov commented Aug 14, 2014

@benedekfazekas Might be useful. I'm not that worried about such problems right now, because as I said earlier, it's quite unlikely that someone would depend directly on tools.namespace and tools.tracing as those are clearly targeting development tools. Right now some people have them in their profiles because previously they've cooked custom elisp that used them, but I doubt this will be an actual issue after cider 0.7 (as the custom code is now redundant).

That said, I'd love to see a solution that would give us the ability to leverage more 3rd party libs without worrying about the dependency conflicts.

@malcolmsparks
Copy link

btw. Almost every project I am involved in developing depends directly on
tools.namespace due to
http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded so
there's that. Plus tools.trace is very useful at times, so many of my
projects use that too. Due to the way Clojure works, we can't use
classloaders to provide isolation between dev tools and runtime (not
necessarily a bad thing) but its a problem here.

On 14 August 2014 13:38, Bozhidar Batsov notifications@github.com wrote:

@benedekfazekas https://github.com/benedekfazekas Might be useful. I'm
not that worried about such problems right now, because as I said earlier,
it's quite unlikely that someone would depend directly on tools.namespace
and tools.tracing as those are clearly targeting development tools. Right
now some people have them in their profiles because previously they've
cooked custom elisp that used them, but I doubt this will be an actual
issue after cider 0.7 (as the custom code is now redundant).

That said, I'd love to see a solution that would give us the ability to
leverage more 3rd party libs without worrying about the dependency
conflicts.


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

@bbatsov
Copy link
Member

bbatsov commented Aug 14, 2014

@malcolmsparks This is the same reason cider uses this library - there's a command to reload your current namespace. Same goes for tracing - we have a tracing command based on it. That's what I meant when I said people used to require those directly, but now don't have to do so.

@malcolmsparks
Copy link

Now I understand, thanks for clarification.

On 14 August 2014 13:53, Bozhidar Batsov notifications@github.com wrote:

@malcolmsparks https://github.com/malcolmsparks This is the same reason
cider uses this library - there's a command to reload your current
namespace. Same goes for tracing - we have a tracing command based on it.
That's what I meant when I said people used to require those directly, but
now don't have to do so.


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

@cichli
Copy link
Member

cichli commented Aug 14, 2014

It may be worth noting that Clojure itself also does something similar with the ASM library to prevent version conflicts (as do Scala and JRuby) - https://github.com/clojure/clojure/tree/master/src/jvm/clojure/asm

benedekfazekas referenced this issue in clojure-emacs/refactor-nrepl Sep 23, 2014
- so dependencies can be included as source and dependency clashes can
  be avoided with projects being refactored
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