Is there a way to gt bb to report in a way that refactor-nrepl undersands?
I RTFM. Sorry about the noise.
Made this experimental malli pod. https://github.com/babashka/pod-babashka-malli
(prn (m/validate [:cat 'int? 'int?] [1 1]))
;; => true
(prn (me/humanize [:cat 'int? 'int?] [1 :foo]))
;; => [nil ["should be an int"]]
$ time bb test.clj
true
[nil ["should be an int"]]
bb test.clj 0.01s user 0.01s system 51% cpu 0.049 total
@borkdude next one
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: force
Location: /Users/wilkerlucio/Development/guardrails/src/main/com/fulcrologic/guardrails/core.cljc:49:8
Phase: analysis
----- Context ------------------------------------------------------------------
45: (let [{:keys [level ?err msg_ ?ns-str ?file hostname_
46: timestamp_ ?line]} data]
47: (str
48: (string/upper-case (name level)) " "
49: (force msg_)
^--- Could not resolve symbol: force
50: (when-let [err ?err]
51: (str "\n" (utils/stacktrace err))))))
52:
53: (defn now-ms [] #?(:clj (System/currentTimeMillis)
54: :cljs (inst-ms (js/Date.))))
That's also a case of juts adding to https://github.com/wilkerlucio/sci/blob/master/src/sci/impl/namespaces.cljc?I'm really surprised that one isn't in there yet. Yes, please add it.
@wilkerlucio Already pushed to sci and bb master
thanks, was about to make it, but you got there faster 🙂
humm, this time I got an error, but that's not pointing to where it happens:
----- Error --------------------------------------------------------------------
Type: java.lang.UnsupportedOperationException
Message: nth not supported on this type: Symbol
is there a verbose/debug way to run to get more details?
Can you make a repro repo for me where I can test this out locally? Usually I discover this by bisecting the code
I'm not sure why the location is missing here. Could be the result of a macro-expansion that is failing to execute
I'm doing that bisect myself, find the file already at least 🙂
@borkdude I believe I found in something related to spartan, this code breaks:
(ns demo
(:require [babashka.deps :as deps]))
(deps/add-deps
'{:deps {borkdude/spartan.spec {:git/url "<https://github.com/borkdude/spartan.spec>"
:sha "bf4ace4a857c29cbcbb934f6a4035cfabe173ff1"}}})
;; Loading spartan.spec will create a namespace clojure.spec.alpha for compatibility:
(require 'spartan.spec)
(alias 's 'clojure.spec.alpha)
(s/def ::args+gspec+body
(s/&
(s/cat :args ::arg-list)
(fn arg-specs-match-param-count? [{:keys [args gspec]}]
true)))
something about using s/&
with a pred
I can reproduce this with:
$ bb -e "(defmacro foo [] \`(do [(nth (symbol :dude) 0)])) (foo)"
----- Error --------------------------------------------------------------------
Type: java.lang.UnsupportedOperationException
Message: nth not supported on this type: Symbol
I mean, the location issue. This is a general problem with macro generated code, there are no locsok, cool, minimum repro at spartan.spec welcome
What is ::arg-list
in this example?
btw, the bug seems related to the name in the function predicate
I'll take a look
Should rewrite-clj
work in babshka?
(deps/add-deps '{:deps {borkdude/rewrite-edn {:mvn/version "0.0.1-alpha.2"}}})
(require '[borkdude.rewrite-edn :as r])
results in an error - seems like .cljc
files are not supported?
----- Error --------------------------------------------------------------------
Type: java.lang.Exception
Message: Could not find namespace: rewrite-cljc.node.
Location: borkdude/rewrite_edn/impl.cljc:3:3
----- Context ------------------------------------------------------------------
1: (ns borkdude.rewrite-edn.impl
2: (:refer-clojure :exclude [assoc update assoc-in update-in])
3: (:require [rewrite-cljc.node :as node]
^--- Could not find namespace: rewrite-cljc.node.
4: [rewrite-cljc.zip :as z]))
5:
6: (defn maybe-right [zloc]
7: (if (z/rightmost? zloc)
8: zloc
Issue fixed.
@nha - rewrite-clj itself doesn't work with babashka. - .cljc files are supported To manipulate code with babashka I recommend using: - https://github.com/babashka/pod-registry/blob/master/examples/parcera.clj
Thanks! I’ll have a look at parcera 🙂
rewrite-clj is quite convenient, maybe one day we could have a sci-based CLI dedicated to it :)
it is 🙂 parcera looks overkill for me as I am just doing some light editing of deps.edn
files
just use rewrite-edn from the JVM I'd say then
I ended up hacking something with parcera btw:
(defn replace-version
"for deps.edn files
ex.
(replace-version \"com.turtlequeue/java-sdk\" \"(str root-dir \"/quickstart/clj/deps.edn\")\" \"1.0.0\")"
[artefact file-path version]
;; <https://github.com/babashka/pod-babashka-parcera/blob/master/examples/zipper.clj>
(let [parsed (parcera/ast (slurp file-path))
zloc (zip/zipper (fn [obj]
(and (seq? obj)
(some-> obj second first keyword?)))
rest
(fn [node children]
(list* (first node) children))
(second parsed))
res (loop [zloc zloc
st {:name-found? false
:mvn-version-found? false}]
(if-not (zip/end? zloc)
(let [node (zip/node zloc)]
#_(when-not (= :whitespace (first node))
(prn node)
(prn (parcera/code node))
(println "STATE " st))
(cond
(= (list :symbol artefact) node)
(recur (zip/next zloc)
(assoc st :name-found? true))
(and
(:name-found? st)
(= '(:keyword ":mvn/version") node))
(recur (zip/next zloc)
(assoc st :mvn-version-found? true))
(and (:name-found? st)
(:mvn-version-found? st)
(seq node)
(= :string (first node))
(string? (second node))
(= 2 (count node)))
(parcera/code (zip/root (zip/replace zloc (list :string (str "\"" version "\"")))))
:default
(recur (zip/next zloc) st)))
(do
(warn "Version not found for " artefact " " file-path " " version)
(parcera/code (zip/root zloc)))))]
(spit file-path res)))
good enough for what I’m doingcool!
😄
Fixed by removing an old hack and replacing it with spec's original code because things have been improving ;)
can I do this with babashka? https://github.com/wilkerlucio/cljc-misc/blob/73844cee606e5fe22f7ab24b7100415090bd5a1d/src/main/com/wsscode/misc/refs.cljc#L29-L44 if I can, how can I reference the Atom class to extend it?