babashka

borkdude 2025-09-04T14:27:38.680249Z

New release! https://clojurians.slack.com/archives/C06MAR553/p1756995848476369

4
lukasz 2025-09-04T14:38:51.390609Z

I'm reading logging impl in BB - I want to use clojure.tools.logging but create my own appender, if I understand correctly - it's a matter of creating my own LoggerFactory, like here?: https://github.com/babashka/babashka/blob/4f2a8aafbf93cfc925c77a426ac1d5f4029387b6/feature-logging/babashka/impl/logging.clj#L278-L287 I want to use JSON as logging format, to make BB emit logs in same way as our JVM apps do

borkdude 2025-09-04T14:51:23.023609Z

It's easier to do this via timbre which is the default logger and plugged into clojure.tools.logging. Let me find some snippets for you

🙏 1
borkdude 2025-09-04T14:52:35.462629Z

ah it's from a thread you asked before :) https://clojurians.slack.com/archives/CLX41ASCS/p1747678325976339?thread_ts=1747671299.406549&cid=CLX41ASCS

lukasz 2025-09-04T14:53:56.891459Z

dang, I knew I was researching this before and lost track of it facepalm

lukasz 2025-09-04T14:54:16.194329Z

thank you, as always

borkdude 2025-09-04T14:54:35.406159Z

well, let's thank @highpressurecarsalesm :)

😊 1
lukasz 2025-09-04T14:58:10.336699Z

indeed :-)

hlship 2025-09-04T20:07:34.079309Z

Problem after upgrading to .208: Has something changed with data-readers in particular, or Vars in general? I set up a custom reader: (set! *data-readers* (assoc *data-readers* 'nu/instant inst)) And, later, in a namespace that sends requests: #(edn/read-string {:readers *data-readers*} %) This worked fine in 1.12.207, but the data-readers has reverted in the second case. Also, tests that read a file with the #nu/instant tag fail for the same reason. I also tried alter-var-root and am getting the same behavior.

✅ 1
borkdude 2025-09-04T20:18:21.287659Z

Yes, something has changed, load-string now binds *data-readers* similar to Compiler/load but this might have introduced a bug. Can you verify if the behavior is different in Clojure and file an issue?

borkdude 2025-09-04T20:19:51.528929Z

I'll take a look at this first thing in the morning

borkdude 2025-09-04T20:20:29.795969Z

> And, later, in a namespace that sends requests: Is that in the same namespace or a different one?

hlship 2025-09-04T20:20:46.853239Z

Also, this is now failing in BB but not Clojure:

(->> "nucli/commands/managed_deps/pulls-response.edn"
                   io/resource
                   slurp
                   (edn/read-string {:readers readers/nu-readers}))
fails with:
ERROR in nucli.commands.managed-deps.repo-test/repo-activity (parser.cljc:555)
Uncaught exception, not in assertion.
Exception: java.lang.Exception: No reader function for tag nu/instant
 at edamame.impl.parser$parse_sharp.invokeStatic (parser.cljc:555)
    edamame.impl.parser$dispatch.invokeStatic (parser.cljc:638)
    edamame.impl.parser$parse_next.invokeStatic (parser.cljc:769)
    edamame.impl.parser$parse_next.invoke (parser.cljc:757)
    edamame.impl.parser$parse_next.invokeStatic (parser.cljc:758)
    edamame.impl.parser$parse_next.invoke (parser.cljc:757)
    edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:248)
    edamame.impl.parser$parse_to_delimiter.invoke (parser.cljc:235)
    edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:237)
    edamame.impl.parser$parse_map.invokeStatic (parser.cljc:574)
    edamame.impl.parser$dispatch.invokeStatic (parser.cljc:672)
    edamame.impl.parser$parse_next.invokeStatic (parser.cljc:769)
    edamame.impl.parser$parse_next.invoke (parser.cljc:757)
    edamame.impl.parser$parse_next.invokeStatic (parser.cljc:758)
    edamame.impl.parser$parse_next.invoke (parser.cljc:757)
    edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:248)
    edamame.impl.parser$parse_to_delimiter.invoke (parser.cljc:235)
    edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:237)
    edamame.impl.parser$parse_map.invokeStatic (parser.cljc:574)
    edamame.impl.parser$dispatch.invokeStatic (parser.cljc:672)
    edamame.impl.parser$parse_next.invokeStatic (parser.cljc:769)
    edamame.impl.parser$parse_next.invoke (parser.cljc:757)
    edamame.impl.parser$parse_next.invokeStatic (parser.cljc:758)
    edamame.impl.parser$parse_next.invoke (parser.cljc:757)
    edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:248)
    edamame.impl.parser$parse_to_delimiter.invoke (parser.cljc:235)
    edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:237)
    edamame.impl.parser$parse_map.invokeStatic (parser.cljc:574)
    edamame.impl.parser$dispatch.invokeStatic (parser.cljc:672)
    edamame.impl.parser$parse_next.invokeStatic (parser.cljc:769)
    edamame.impl.parser$parse_next.invoke (parser.cljc:757)
    edamame.impl.parser$parse_next.invokeStatic (parser.cljc:758)
    edamame.core$parse_next.invokeStatic (core.cljc:126)
    sci.impl.parser$parse_next$fn__3133.invoke (parser.cljc:166)
    sci.impl.parser$parse_next.invokeStatic (parser.cljc:166)

hlship 2025-09-04T20:22:16.064769Z

So problem #1 is related to *data-readers* value reverting after the call to set!. Problem #2 seems to be clojure.edn/read-string ignoring the :readers option.

borkdude 2025-09-04T20:22:32.111569Z

is that a new problem or was it already in bb?

hlship 2025-09-04T20:23:52.341639Z

In .207 all I needed was the set! of *data-readers* and that code was using clojure.core/read-string not clojure.edn/read-string.

borkdude 2025-09-04T20:24:17.845829Z

can you make an isolated repro to avoid confusion?

hlship 2025-09-04T20:24:39.624309Z

Yes, let me put something together.

borkdude 2025-09-04T20:24:47.890459Z

I'm not sure if the example earlier intended to be read-string or edn/read-string. edn/read-string should not print anything related to edamame

borkdude 2025-09-04T20:40:08.894759Z

Here's a little test case:

borkdude@MBP25-2 ~/dev/scratch/data_reader $ cat src/foo.clj
(ns foo)

(set! *data-readers* (assoc *data-readers* 'foo/bar identity))

(require 'bar)

(defn exec [_]
  (prn bar/x))
borkdude@MBP25-2 ~/dev/scratch/data_reader $ cat src/bar.clj
(ns bar)

(def x #foo/bar [1 2 3])
borkdude@MBP25-2 ~/dev/scratch/data_reader $ clj -X foo/exec
[1 2 3]
borkdude@MBP25-2 ~/dev/scratch/data_reader $ bb -cp src -x foo/exec
[1 2 3]
How is your test case different?

borkdude 2025-09-04T20:42:51.553269Z

and this fails in both clj + bb:

(ns foo
  (:require [clojure.edn :as edn]))

(set! *data-readers* (assoc *data-readers* 'foo/bar identity))

(require 'bar)

(defn exec [_]
  (prn bar/x)
  (prn *data-readers*)
  (prn (edn/read-string {:readers *data-readers*} "#foo/bar [1 2 3]")))
(added the edn/read-string call. This is because *data-readers* is no longer bound to the value you set at the top level. It's re-bound to the original, same behavior as Clojure

borkdude 2025-09-04T20:43:39.927939Z

This does work in both clj + bb:

(prn (edn/read-string {:readers (assoc *data-readers* 'foo/bar identity)} "#foo/bar [1 2 3]"))

hlship 2025-09-04T20:44:11.125269Z

So, possibly my code was invalid but still worked in .207. Just about have a test case for you, but nothing new compared to your notes above.

borkdude 2025-09-04T20:44:37.615259Z

Yes, this was "fixed" in bb to align more with JVM Clojure

hlship 2025-09-04T20:45:24.147429Z

Ok. I'm only about 15 years into Clojure, I'm sure I'll figure out how Vars get bound in a REPL soon. 😞

borkdude 2025-09-04T20:46:14.873059Z

the issue that was previously there was that in threads, *data-readers* would not be bound correctly in a future:

(prn @(future (load-string "*data-readers*")))
This would fail. Actually the example I encountered before was *warn-on-reflection* but same problem.

borkdude 2025-09-04T20:46:29.328079Z

If you still have something that isn't conform clojure with respect to Vars, happy to hear it.

hlship 2025-09-04T20:49:38.652049Z

Ok, I was totally panicing on the edn/read-string part. Turns out I had a second test using read-string that also needed to switch to edn/read-string.

borkdude 2025-09-04T20:53:39.386319Z

Glad we sorted it out 😅

borkdude 2025-09-04T20:55:06.851289Z

and sorry for the inconvenience

hlship 2025-09-04T20:55:27.173069Z

Nah, this was all me. Thanks for helping me sort it out.