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

Name collision causes an exception during debugging #846

Closed
darkleaf opened this issue Feb 4, 2024 · 2 comments · Fixed by #847
Closed

Name collision causes an exception during debugging #846

darkleaf opened this issue Feb 4, 2024 · 2 comments · Fixed by #847

Comments

@darkleaf
Copy link
Contributor

darkleaf commented Feb 4, 2024

I use di in my project and there is a lot of code like this

(ns debugger-example)

(defn service [-deps a b]
  [a b])

;; C-u C-M-x
(defn caller [{service  `service
               service* `service}]
  [(service* 1 2)
   (service  1 2)]) ;; => works without debugger [[1 2] [1 2]]

(comment
  (caller {`service (partial service :unused-deps)})
  ,,,)

Unfortunately, I can't use the debugger.

Expected behavior

I can successfully execute caller with debugger mode.

Actual behavior

It shows value of (service* 1 2) but fails on (service 1 2).

Снимок экрана 2024-02-04 в 18 45 15
1. Unhandled clojure.lang.ArityException
   Wrong number of args (2) passed to: debugger-example/service

                  AFn.java:  429  clojure.lang.AFn/throwArity
                  AFn.java:   36  clojure.lang.AFn/invoke
                  AFn.java:  156  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  Var.java:  707  clojure.lang.Var/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj:  662  clojure.core/apply
                 debug.clj:  542  cider.nrepl.middleware.debug/apply-instrumented-maybe
                 debug.clj:  538  cider.nrepl.middleware.debug/apply-instrumented-maybe
                      REPL:    7  debugger-example/eval23279/caller
                      REPL:   12  debugger-example/eval23283
                      REPL:   12  debugger-example/eval23283
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7132  clojure.lang.Compiler/eval
                  core.clj: 3229  clojure.core/eval
                  core.clj: 3225  clojure.core/eval
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 1990  clojure.core/with-bindings*
                  core.clj: 1990  clojure.core/with-bindings*
               RestFn.java:  428  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  459  clojure.main/repl/fn
                  main.clj:  459  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1526  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  218  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  217  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java: 1583  java.lang.Thread/run

Environment & Version information

cider-nrepl version

  • cider-nrepl 0.45.0
  • CIDER 1.13.1 (Santiago)
  • nREPL 1.0.0

Java version

21.0.1

Operating system

mac os x 13.6.1

@vemv
Copy link
Member

vemv commented Feb 4, 2024

Interesting, thanks!

Worth noting, service (the local variable) shadows service (the var).

Linters such as clj-kondo https://github.com/clj-kondo/clj-kondo/blob/b5c63bfc9ee0066b202945a6186749af8e66af6e/doc/linters.md#shadowed-var and Eastwood https://github.com/jonase/eastwood?tab=readme-ov-file#local-shadows-var can lint against that kind of thing, as it's commonly frowned upon practice.

I'm not saying "don't do that", but generally, misc tooling will work better when following the best practice.

Most practically, here it means that you might not get support quickly (the debugger middleware doesn't often get maintenance).

@vemv
Copy link
Member

vemv commented Feb 4, 2024

Sure, thanks! We can figure out how to add a test as you open the PR.

darkleaf added a commit to darkleaf/cider-nrepl that referenced this issue Feb 4, 2024
darkleaf added a commit to darkleaf/cider-nrepl that referenced this issue Feb 4, 2024
darkleaf added a commit to darkleaf/cider-nrepl that referenced this issue Feb 4, 2024
@vemv vemv closed this as completed in #847 Feb 21, 2024
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

Successfully merging a pull request may close this issue.

2 participants