Zulu-Inuoe / jzon

A correct and safe(er) JSON RFC 8259 reader/writer with sane defaults.
MIT License
151 stars 14 forks source link

stringify on recursive structures #9

Closed Zulu-Inuoe closed 1 year ago

Zulu-Inuoe commented 3 years ago

stringify dies on recursive structures:

(h:define-easy-handler (test :uri (h:create-prefix-dispatcher "/test" t)) ()
  (standard-page "Hello?"
    (jzon:stringify h:*request* :pretty t)))
Control stack guard page temporarily disabled: proceed with caution
[2021-03-21 21:45:02 [ERROR]] Error while processing connection: The condition The condition Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.

PROCEED WITH CAUTION. occurred with errno: 0. occurred with errno: 0.

At the very least we should have circularity detection by default. per what to do when it's encountered, I am leaning towards having these two options available:

  1. Silently produce a string with an 'obviously' wrong value, such as "recursive-ref__request->easy-acceptor->one-thread-per-connection-taskmaster->easy-acceptor".
  2. Signal an error with a restart available asking for a value to substitute.

By default, I prefer the 'fail silently' option since it's more DWIM when a user is simply trying to inspect some object

Zulu-Inuoe commented 1 year ago

So I've decided to 180 on this and keep error-ing on circular references per the spec for in-browser JSON.stringify: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

This is simpler and likely less controversial