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

Imitate clojure.main Error Reporting #1004

Open
lambrospetrou opened this issue Aug 14, 2019 · 1 comment
Open

Imitate clojure.main Error Reporting #1004

lambrospetrou opened this issue Aug 14, 2019 · 1 comment

Comments

@lambrospetrou
Copy link

lambrospetrou commented Aug 14, 2019

I was writing a small function to traverse a binary tree and due to an extra parentheses somewhere in the code I kept getting the following error:

Execution error (Error) at (<cljs repl>:1).
Invalid arity: 0

Without any hint on the line or in the macro/function that the erroneous function call happened it was very hard to find the mistake. I eventually did find it after a few hours but it would be great if the error message was more descriptive and could include some more details.

Unfortunately, I don't have experience with the ClojureScript compile or internal implementation of the macros so I don't really know if there even exists any information during runtime that could be useful but I thought it would be great to expose it if there was.

The code throwing this error is below:

; `repro.cljs`
(ns solutions.daily-coding-problem.repro)

(defn deepest-node [root]
  (defn do-deep-rec [n, depth]
    (cond
      (nil? n) [nil 0]
      (and (nil? (:l n)) (nil? (:r n))) [n depth]
      :else (
        (let [
          [ln ld] (do-deep-rec (:l n) (inc depth))
          [rn rd] (do-deep-rec (:r n) (inc depth))]
          (if (> ld rd)
            [ln ld]
            [rn rd])))))
  (get (do-deep-rec root 1) 0))

(println (:val (deepest-node 
  {
    :val "a",
    :l {
      :val "b"
      :l { :val "d" }
    },
    :r {:val "c"}
  })))

After saving the above into repro.cljs, running the code with plk repro.cljs will generate the error.

The problem is an extra pair of parentheses for the :else clause, so removing those fixes the problem and the code runs fine.

Thanks a lot.

@mfikes
Copy link
Member

mfikes commented Aug 15, 2019

My initial hunch is that we should make this scenario behave like Clojure 1.10.1 (putting more details into a temp edn file that is referenced when the exception summary is printed).

Details: https://github.com/clojure/clojure/blob/8f03ff0078dda9fb3923ff0c4ee5a101570b8485/changes.md#12-clojuremain-error-reporting

@mfikes mfikes changed the title Better error message for Invalid arity: 1 Imitate clojure.main Error Reporting Aug 17, 2019
mfikes added a commit that referenced this issue Aug 17, 2019
mfikes added a commit that referenced this issue Aug 18, 2019
mfikes added a commit that referenced this issue Aug 18, 2019
mfikes added a commit that referenced this issue Aug 18, 2019
mfikes added a commit that referenced this issue Aug 19, 2019
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

2 participants