# Debugging input port

**URL:** <https://racket.discourse.group/t/debugging-input-port/2357>\
**Category:** General\
**Created:** [October 2, 2023, 9:07am UTC](https://racket.discourse.group/t/debugging-input-port/2357 "2023-10-02T09:07:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [October 2, 2023, 9:07am UTC](https://racket.discourse.group/t/debugging-input-port/2357/1 "2023-10-02T09:07:58Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![bogdan](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bogdan/32/8_2.png) [@bogdan](https://racket.discourse.group/u/bogdan)\
**Post date:** [October 2, 2023, 9:38am UTC](https://racket.discourse.group/t/debugging-input-port/2357/2 "2023-10-02T09:38:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [October 2, 2023, 9:57am UTC](https://racket.discourse.group/t/debugging-input-port/2357/3 "2023-10-02T09:57:43Z")

</div>

Oh wow, thanks! You even named it `make-debug-input-port` 😃
