Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions raised in a custom-write write-proc can cause infinite recursion #4285

Closed
MarkHedlund opened this issue Jun 6, 2022 · 4 comments

Comments

@MarkHedlund
Copy link
Contributor

MarkHedlund commented Jun 6, 2022

What version of Racket are you using?
v8.5.0.8 [cs] on Linux x86_64

What program did you run?

(require racket/struct)

(struct a (b)
  #:methods gen:custom-write
  [(define (write-proc s port mode)
     (print (struct->list s) port mode))])

(a 1)

struct->list by default raises an exception when given an opaque struct, which itself tries to write the struct instance, and the recursion begins. Keep an eye on your memory when that is happening.

What should have happened?
Maybe it is best to simply give users a warning in the documentation. Otherwise, perhaps this could be handled by detecting the recursion with a parameter somewhere in the custom-write or pretty.rkt code. After detection, another exception could be raised instead.

@MarkHedlund
Copy link
Contributor Author

I made an edit to the program examples for simplicity.

Normally I'd say that this recursion problem is the users' responsibility to address, but because it's kind of sneaky and error values are not always thoroughly documented, it seemed surprising and I thought I should post it.

@MarkHedlund
Copy link
Contributor Author

This issue does not appear to be viewed as something to be addressed at the language level, so I'm closing it out of the way. Going forward, if I encounter similar scenarios I will first ask about them on Discourse to determine their worthiness as an issue.

@gus-massa
Copy link
Contributor

I don't think this is a bad report. But I'm not sure if it can be fixed, how it can be fixed, and if it's a good idea to fix it.

A perfect fix is impossible, but perhaps give up after 5 or 10 recursive errors in the error report? Can that break something? Can it be annoying in some weird corner case? I'll not make any attempt to fix this, but it's one of those things that would be nice to keep in mind.

@MarkHedlund
Copy link
Contributor Author

Okay. I'm just glad that I was not entirely wrong for reporting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants