nrepl

jasalt 2025-03-13T18:22:25.125339Z

Hi. Started working on server for Phel. https://github.com/arokettu/bencode/blob/7bd5447c34846476822c01cb62c0765f94a89e8c/src/Engine/Reader.php#L185C18-L185C19 seems too strict and throws errors with Cider/Calva because dict keys are not in alphabetical order e.g. 'id' after 'op' or 'code' after 'op'. Bencode spec seems to have that sort of restriction, but here it's not that strictly followed I assume? Maybe need to change the library, not seeing it has less strict parsing option regarding that.

oyakushev 2025-03-13T18:31:42.592939Z

Bencode indeed is a canonical-representation format (which means equal objects are encoded into equal strings). That requires dictionary keys to be sorted.

oyakushev 2025-03-13T18:32:10.797769Z

What do you mean by "but here it's not that strictly followed I assume"? Where's "here", the nREPL?

jasalt 2025-03-13T18:33:19.557109Z

Ah, yes, I mean in nREPL server context / editor clients.

oyakushev 2025-03-13T18:34:31.756699Z

I still don't fully understand. You are right on one part for sure – nrepl server doesn't validate the order of keys in incoming messages to the server. But it produces valid outgoing messages.

oyakushev 2025-03-13T18:34:57.617969Z

So what's the problem again, where do you get malformed message from that your library barks on them?

jasalt 2025-03-13T18:36:35.913969Z

Hmm. Looking what I receive on connect, seems that both of these editors are sending op key first. Cider: d2:op5:clone2:id1:210:time-stamp29:2025-03-13 19:56:04.740577794e Calva: d2:op4:eval4:code4:*ns*2:id1:1e

oyakushev 2025-03-13T18:38:18.100069Z

I see, it is indeed a client-side issue then.

oyakushev 2025-03-13T18:39:47.261099Z

Yeah, I can see in the CIDER code that it doesn't attempt to sort the keys. That's not cool, even if it didn't cause problems before.

jasalt 2025-03-13T18:40:46.284179Z

Interesting finding then. Seems that PHP folks can be pedantic about certain things, hehe. Error what I get:

Arokettu\Bencode\Exceptions\ParseErrorException: Invalid order of dictionary keys: 'code' after 'op' in /home/user/dev/phel-nrepl/vendor/arokettu/bencode/src/Engine/Reader.php

oyakushev 2025-03-13T18:41:41.724829Z

Yeah. We never used the canonical representation property in CIDER or nrepl, but a spec is a spec, you have to adhere to it. @bozhidar We should fix this, what do you think?

oyakushev 2025-03-13T18:42:43.120449Z

It might be a while till we sort this out (sort... hehe), so you indeed might have better luck finding a more lax library in the meantime.

jasalt 2025-03-13T18:43:33.826309Z

Yea, not a big trouble, thank's.

oyakushev 2025-03-13T18:47:19.715509Z

https://github.com/clojure-emacs/cider/issues/3786

oyakushev 2025-03-13T18:48:25.565619Z

In this day an age, you may reasonably ask chatgpt to roll you a simple Bencode parser in PHP and embed it into your project. The whole thing will be very small.

jasalt 2025-03-13T19:05:05.987189Z

@alexyakushev Yes, seems it got sorted (ha-ha), with another lib https://github.com/Rhilip/Bencode/blob/master/src/Bencode.php#L66

👍 1
bozhidar 2025-03-16T05:19:26.537319Z

@alexyakushev Yeah, we should probably fix it - as you said it “a spec is a spec”. 🙂