babashka / neil

A CLI to add common aliases and features to deps.edn-based projects
MIT License
377 stars 27 forks source link

`neil dep add` crashes if there's metadata on the `:deps` map #239

Open teodorlu opened 3 months ago

teodorlu commented 3 months ago

Reproduction

$ cat deps.edn 
{:deps ^{:teodor/nonsense :YES} {hiccup/hiccup {:mvn/version "1.0.5"}}}

clj appears to be fine with metadata on the deps map:

$ clj -e '{:ok true}'
WARNING: Implicit use of clojure.main with options is deprecated, use -M
{:ok true}

Expected

http-kit dep is added.

Actual

neil dep add crashes:

$ neil dep add http-kit
----- Error --------------------------------------------------------------------
Type:     java.lang.ClassCastException
Message:  clojure.lang.Symbol cannot be cast to java.lang.Number
Location: borkdude/rewrite_edn/impl.cljc:154:13

----- Context ------------------------------------------------------------------
150:                           (iterate z/right)
151:                           (take-while identity)
152:                           (remove #(or (node/whitespace-or-comment? %)
153:                                        (= :uneval (node/tag %)))))]
154:         (if (>= k (count coll))
                 ^--- clojure.lang.Symbol cannot be cast to java.lang.Number
155:           (node/coerce default)
156:           (node/coerce (first (nth coll k))))))))
157: 
158: (defn get-in [zloc ks not-found]
159:   (reduce (fn [zloc k]

----- Stack trace --------------------------------------------------------------
clojure.core/>=                  - <built-in>
borkdude.rewrite-edn.impl/get    - borkdude/rewrite_edn/impl.cljc:154:13
borkdude.rewrite-edn.impl/get    - borkdude/rewrite_edn/impl.cljc:119:1
borkdude.rewrite-edn.impl        - borkdude/rewrite_edn/impl.cljc:162:23
clojure.core/reduce              - <built-in>
... (run with --debug to see elided elements)
babashka.neil                    - /opt/homebrew/bin/neil:1294:27
babashka.neil/-main              - /opt/homebrew/bin/neil:1742:3
babashka.neil/-main              - /opt/homebrew/bin/neil:1741:1
babashka.neil                    - /opt/homebrew/bin/neil:1804:3
babashka.neil                    - /opt/homebrew/bin/neil:1803:1

Does the namespaced map matter?

I still get a crash without a namespaced map in the metadata:

$ cat deps.edn 
{:deps ^{:teodor-nonsense :YES} {hiccup/hiccup {:mvn/version "1.0.5"}}}
$ neil dep add http-kit
----- Error --------------------------------------------------------------------
Type:     java.lang.ClassCastException
Message:  clojure.lang.Symbol cannot be cast to java.lang.Number
Location: borkdude/rewrite_edn/impl.cljc:154:13

----- Context ------------------------------------------------------------------
150:                           (iterate z/right)
151:                           (take-while identity)
152:                           (remove #(or (node/whitespace-or-comment? %)
153:                                        (= :uneval (node/tag %)))))]
154:         (if (>= k (count coll))
                 ^--- clojure.lang.Symbol cannot be cast to java.lang.Number
155:           (node/coerce default)
156:           (node/coerce (first (nth coll k))))))))
157: 
158: (defn get-in [zloc ks not-found]
159:   (reduce (fn [zloc k]

----- Stack trace --------------------------------------------------------------
clojure.core/>=                  - <built-in>
borkdude.rewrite-edn.impl/get    - borkdude/rewrite_edn/impl.cljc:154:13
borkdude.rewrite-edn.impl/get    - borkdude/rewrite_edn/impl.cljc:119:1
borkdude.rewrite-edn.impl        - borkdude/rewrite_edn/impl.cljc:162:23
clojure.core/reduce              - <built-in>
... (run with --debug to see elided elements)
babashka.neil                    - /opt/homebrew/bin/neil:1294:27
babashka.neil/-main              - /opt/homebrew/bin/neil:1742:3
babashka.neil/-main              - /opt/homebrew/bin/neil:1741:1
babashka.neil                    - /opt/homebrew/bin/neil:1804:3
babashka.neil                    - /opt/homebrew/bin/neil:1803:1