babashka

dharrigan 2025-06-04T14:54:11.256319Z

Searching through history, I see a couple of posts from people being unable to run something because of things that core.cache uses. I'm hitting a similar issue - I'm trying to use a library that depends upon memoize that depends upon cache and I'm getting Unable to resolve classname: java.lang.ref.SoftReference. Any chance this could be added? Happy to be told there's another way 🙂

borkdude 2025-06-04T15:00:43.630079Z

I'd be happy to add it if it would make the complete scenario of what you're trying to do work. What is this complete scenario?

dharrigan 2025-06-04T15:01:53.232759Z

Using randomseed-io/phone-number to parse over 100,000 phone numbers for validity.

dharrigan 2025-06-04T15:02:29.939539Z

Thus, reading from the db (thanks mysql pod), parsing each number in turn for compliance and country specific formatting, then saving somewhere else.

dharrigan 2025-06-04T15:02:30.991849Z

.

borkdude 2025-06-04T15:05:23.286159Z

it seems that this library depends on a lot of Java stuff that's not available in bb, probably?

io.randomseed/phone-number 8.13.6-3
  . com.googlecode.libphonenumber/geocoder 2.200
    . com.googlecode.libphonenumber/libphonenumber 8.13.6
    . com.googlecode.libphonenumber/prefixmapper 2.200
  . com.googlecode.libphonenumber/carrier 1.190
    . com.googlecode.libphonenumber/libphonenumber 8.13.6
    . com.googlecode.libphonenumber/prefixmapper 2.200
  . malabarba/lazy-map 1.3
  . com.googlecode.libphonenumber/libphonenumber 8.13.6
  . com.googlecode.libphonenumber/prefixmapper 2.200
    . com.googlecode.libphonenumber/libphonenumber 8.13.6
  . org.clojure/core.memoize 1.0.257
    . org.clojure/core.cache 1.0.225
      . org.clojure/data.priority-map 1.1.0
  . trptr/java-wrapper 0.2.3

dharrigan 2025-06-04T15:06:17.842839Z

I've pulled in libphonenumber as a dep, but doing the checking falls over immediately with the cache/soft-reference missing class.

dharrigan 2025-06-04T15:06:36.217719Z

I could just do this in plain old clj I guess, but I was trying to see if I could do this faster in bb.

borkdude 2025-06-04T15:10:44.284219Z

this is because it didn't reach the Java lib problem yet, it first stumbles over the Softref thing missing. The next error you'll see is:

$ clj -M:babashka/dev -Sdeps '{:deps {io.randomseed/phone-number {:mvn/version "8.13.6-3"}}}' -e "(require '[phone-number.core :as phone])"
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  defrecord/deftype currently only support protocol implementations, found: clojure.lang.ILookup

borkdude 2025-06-04T15:10:57.950259Z

core core/cache.clj

borkdude 2025-06-04T15:13:38.330649Z

I could add core.cache + core.memoize as built-ins in bb which makes sense since it would enable running more libraries but then you would still hit the Java class problem e.g. here: https://github.com/randomseed-io/phone-number/blob/9ae592c0517a92d66534f0f62c291b21f02be58e/src/phone_number/locale.clj#L14

dharrigan 2025-06-04T15:13:50.081809Z

np, I'll switch to clj

borkdude 2025-06-04T15:13:53.219079Z

so yeah in this case it's better to just use clj

dharrigan 2025-06-04T15:13:57.223789Z

ta

sheluchin 2025-06-04T17:28:06.178649Z

What's happening here?

$ bb -m cli.foo
2025-06-04T17:23:20.132Z alex DEBUG [cli.foo:5] - x
$ bb -m cli.foo
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: log/set-min-level!
Data:     {:type :sci/error, :line 4, :column 1, :file ".../cli/foo.clj", :phase "analysis"}
Location: .../cli/foo.clj:6:3
Phase:    analysis

----- Context ------------------------------------------------------------------
2:   (:require [taoensso.timbre :as log]))
3: 
4: (defn -main []
5:   (log/debug "x")
6:   (log/set-min-level! :error)
     ^--- Could not resolve symbol: log/set-min-level!
7:   (log/debug "x"))

----- Stack trace --------------------------------------------------------------
cli.foo/fn - .../cli/foo.clj:6:3
clojure.core/fn             - <built-in>
cli.foo    - .../cli/foo.clj:4:1
clojure.core/defn           - <built-in>
cli.foo    - .../cli/foo.clj:4:1
cli.foo    - .../cli/foo.clj:4:1
user                        - <expr>:1:10
Why is it that I can execute this fine when doing it interactively through a bb nrepl-server but it doesn't work when calling the main fn?

borkdude 2025-06-04T17:35:55.660279Z

can you give me the text of the entire script?

sheluchin 2025-06-04T17:36:37.448849Z

(ns cli.foo
  (:require [taoensso.timbre :as log]))

(defn -main []
  (log/debug "x")
  (log/set-min-level! :error)
  (log/debug "x"))

borkdude 2025-06-04T17:39:52.269669Z

I think in the nREPL in bb at least this doesn't work either: (taoensso.timbre/set-min-level! :error) since that var probably doesn't exist in bb.

(get (ns-publics 'taoensso.timbre) 'set-min-level!)

borkdude 2025-06-04T17:40:42.431799Z

you can set the level with this:

(ns dude
  (:require [taoensso.timbre :as log]))

(defn -main []
  (log/debug "x")
  (log/merge-config! {:min-level :error})
  (log/debug "x"))

sheluchin 2025-06-04T17:43:23.524969Z

Hmm, maybe I tried it in a Clojure nREPL and got them mixed up. Could you explain why set-min-level! isn't available but merge-config! is? It's a little surprising to me. I guess to make a lib bb-compatible you expose some specific vars from the lib, but not all?

borkdude 2025-06-04T17:46:19.867619Z

timbre is a very non-typical library with lots of macros and dynamic vars so it's complicated to make it work in bb. at the time (4 years ago) I only did the work to make the most used functions/macros work in bb

(def timbre-namespace
  (assoc (make-ns 'taoensso.timbre tns ['trace 'tracef 'debug 'debugf
                                        'info 'infof 'warn 'warnf
                                        'error 'errorf
                                        '-log! 'with-level
                                        'spit-appender '-spy 'spy
                                        'color-str])
         'log! (sci/copy-var log! tns)
         '*config* config
         'swap-config! (sci/copy-var swap-config! tns)
         'merge-config! (sci/copy-var merge-config! tns)
         'set-level! (sci/copy-var set-level! tns)
         'println-appender (sci/copy-var println-appender tns)
         '-log-and-rethrow-errors (sci/copy-var -log-and-rethrow-errors tns)
         '-ensure-vec (sci/copy-var encore/ensure-vec tns)))
we could easily add the function you're missing though

borkdude 2025-06-04T17:47:17.673659Z

seems like it has come up only once before this conversation: https://clojurians.slack.com/archives/CLX41ASCS/p1729004660283259?thread_ts=1728982742.755019&amp;cid=CLX41ASCS

sheluchin 2025-06-04T17:49:01.721759Z

So there's no easy way to really tell if you're running into this sort of thing, right? Kind of just have to see such a surprising result and then look in the bb code to see if the var has copy-var called on it?

sheluchin 2025-06-04T17:50:10.699579Z

It's no big deal to use merge-config! here instead of the set-min-level!, I'm just trying to understand the how to go about it if I run into a similar situation in the future.

borkdude 2025-06-04T17:50:56.832049Z

yep

borkdude 2025-06-04T17:51:11.948259Z

we can add set-min-level, makes sense to add it. I'll try to do it now

sheluchin 2025-06-04T17:51:44.683619Z

Maybe this would be a good candidate for a custom clojure-lsp linter.

sheluchin 2025-06-04T17:52:43.173769Z

or could this be a general type of linter in kondo itself?

borkdude 2025-06-04T17:52:45.762589Z

hmm there is also a set-level! function which seems to do the same? it's available in bb now

sheluchin 2025-06-04T17:53:12.036219Z

yeah timbre seems to have a lot of ways to go about doing it

sheluchin 2025-06-04T17:53:33.267689Z

Intend to try out Telemere sometime anyway

borkdude 2025-06-04T17:54:07.246999Z

I think set-level! should have been added as set-min-level! , probably I made a typo here, since set-level! doesn't exist in timbre

sheluchin 2025-06-04T17:54:41.353489Z

lol so I'm not the only one who makes typos huh

sheluchin 2025-06-04T17:55:07.711729Z

Okay borkdude, many thanks for your advice and direction.

borkdude 2025-06-04T18:00:10.762319Z

It seems I didn't completely make this up: https://github.com/Flexiana/framework/blob/b2ff4ce47ad9f417ff26be37cd85592b7c11ca4d/src/xiana/db/migrate.clj#L152

borkdude 2025-06-04T18:00:39.167229Z

but I can't find it in the API here: https://taoensso.github.io/timbre/taoensso.timbre.html#var-set-config.21

sheluchin 2025-06-04T18:00:46.435979Z

It... looks familiar to me too.

borkdude 2025-06-04T18:01:55.005819Z

apparently a rename:

98deeb73 [mod] [DEPRECATE] set-level! -> set-min-level!, with-level -> with-min-level

sheluchin 2025-06-04T18:02:15.219989Z

yep was just looking at that

sheluchin 2025-06-04T18:02:41.688369Z

so you don't make typos 😒

borkdude 2025-06-04T18:03:04.304749Z

just not in this case ;)

sheluchin 2025-06-04T18:04:23.029199Z

I guess there could be some value in having an easy way to know if popular var disappears from some lib.

borkdude 2025-06-04T18:04:47.630329Z

it didn't disappear but was deprecated

borkdude 2025-06-04T18:05:04.303009Z

https://github.com/borkdude/api-diff

🤔 1
sheluchin 2025-06-04T18:05:45.609249Z

I hadn't seen that one yet.

borkdude 2025-06-04T18:13:32.339129Z

anyway, fixed on master now

🙌 1