Debugging input port

Frequently, I get an error from (read in), but it's difficult to see what goes wrong. I can try to use peek-... on in to help debugging, but that's also not convenient because I need to specify how many bytes I want to read, which is not always possible.

Has anyone created a solution to this problem?

Ideally, I want a function make-debug-input-port. (make-debug-input-port in) redirects every port operation to in, but it emits debugging information on port operations. Has anyone done this before?

(I attempted to create it, but gave up after reading the make-input-port doc. It's too dense for me to wrap my head around).

I've done this for one of my projects: https://github.com/Bogdanp/Noise/blob/174a7dd8d8f2686920332da71eb4fc84fa1e3f7b/Racket/noise-serde-lib/private/debug.rkt

1 Like

Oh wow, thanks! You even named it make-debug-input-port :smiley:

2 Likes