Fork me on GitHub
#babashka
<
2020-05-12
>
sogaiu02:05:10

i'd like to see the bytes being exchanged between bb and a pod. is there some kind of debug functionality along these lines?

borkdude07:05:44

@sogaiu it all works over stdin and stdout. So you can just send some bencode to the pods stdin and watch the output

sogaiu07:05:02

i want to see what other pods are doing

sogaiu07:05:08

the docs are not enough for me to figure things out

borkdude07:05:32

Alternatively you can use the babashka.pods library and put some printlines in there

borkdude07:05:46

And run it on the JVM

sogaiu07:05:32

i am not using clojure to do this

borkdude07:05:00

You are not loading the pod from Clojure?

sogaiu07:05:18

i am loading the pod from babashka -- the pod is not written in clojure

borkdude07:05:38

Then what I’ve said before still stands

borkdude07:05:28

Just look at the tests of the filewatcher for example

borkdude07:05:05

Those run on the JVM while the fw is written in Rust

sogaiu07:05:08

i will go back and look again

sogaiu07:05:20

thanks for the hints

sogaiu07:05:22

because stdin and stdout are already being used, print didn't seem like it was going to work. what i ended up doing was this:

(defn write [^.OutputStream stream v]
  (spit "/tmp/pod.log"
        (str "wrote: " v "\n")
        :append true)
  (locking stream
    (bencode/write-bencode stream v)
    (.flush stream)))

(defn read [stream]
  (let [res (bencode/read-bencode stream)]
    (spit "/tmp/pod.log"
          (str "read: " res "\n")
          :append true)
    res))
with appropriate rebuilding (i guess the uberjar script?) this appears to allow one to observe what's taking place between bb and a pod

borkdude07:05:55

@sogaiu that works, but like I said, if you use the babashka.pods library you can just do this on the JVM without rebuilding

sogaiu07:05:09

i think from where you sit it probably seems easy because you understand all of the bits already 🙂 for someone who is in the midst of trying to figure out other pieces (and someone like me with limited stack space and capability 🙂 ), it was too many uncertain pieces.

sogaiu07:05:15

in any case, thanks for the tips

borkdude07:05:56

@sogaiu Changing these lines in the JVM library is easier, since you don't need to rebuild the entire babashka. it's more flexible

sogaiu07:05:23

it is easier to you because you already understand

borkdude07:05:20

so changing a line in bb, compiling it with GraalVM, needing another change, compiling it again with GraalVM is more difficult then doing exactly the same thing in running a JVM program? that really doesn't make sense to me 😉

borkdude07:05:43

look: this test is just ran on the JVM: https://github.com/babashka/pod-babashka-filewatcher/blob/master/test/pod/babashka/filewatcher_test.clj it does exactly the same thing as within bb.

borkdude07:05:14

but suit yourself 🙂

sogaiu07:05:18

there is no disagreement about IF you understand the alternatives which one would be easier. i believe what you say. the problem is when one's stack space is full holding a lot of other details, trying to understand additional alternatives can be too much. basically, the issue is a cognitive problem on my side 🙂

borkdude07:05:15

that makes sense

borkdude07:05:01

@sogaiu This also works:

$ BABASHKA_POD=true clj-kondo <<< $(bb -e '(bencode/write-bencode System/out {"op" "describe"})')
d6:format3:edn2:id7:unknown10:namespacesld4:name22:pod.borkdude.clj-kondo4:varsld4:name13:merge-configsed4:name6:print!ed4:name4:run!eeeee

borkdude07:05:13

You can then pipe the output back into something like:

$ BABASHKA_POD=true clj-kondo <<< $(bb -e '(bencode/write-bencode System/out {"op" "describe"})') | bb -e '(bencode/read-bencode (.PushbackInputStream. System/in))'
{"format" #object["[B" 0x545ac490 "[[email protected]"], "id" #object["[B" 0x30ffb9b0 "[[email protected]"], "namespaces" [{"name" #object["[B" 0x77363113 "[[email protected]"], "vars" [{"name" #object["[B" 0xec59d35 "[[email protected]"]} {"name" #object["[B" 0x4478964a "[[email protected]"]} {"name" #object["[B" 0x34bb1efa "[[email protected]"]}]}]}

borkdude07:05:46

This way you can develop a small bb script which interacts with your pod

sogaiu07:05:12

thanks -- i will have to digest these things later when my stack is not so full 🙂

borkdude07:05:46

it is similar to the nREPL protocol

borkdude08:05:51

@sogaiu One other hint: you can print to sterr in the pod for debugging as well

sogaiu08:05:04

yeah, i've been doing that since the first run, thanks 🙂

sogaiu08:05:14

at least from the pod side

borkdude08:05:33

there is also a python pod example

borkdude08:05:39

don't know which language you're writing the pod in

sogaiu10:05:14

yes, i've been looking at the python example too.

sogaiu10:05:21

i'm writing it in janet

nate17:05:38

very cool