DZakh / rescript-schema

🧬 The fastest parser in the entire JavaScript ecosystem with a focus on small bundle size and top-notch DX
MIT License
156 stars 7 forks source link

RangeError: Maximum call stack size exceeded when serializing complex recursive union schemas. #74

Closed TomiS closed 3 months ago

TomiS commented 4 months ago

Hey, I ran into this rather interesting bug which originates to validateJsonableSchema function, I believe. I think it relates to wrapping a recursive (union?) schema inside a non-recursive schema. Or at least that's how I can cause the bug reliably.

I made a somewhat minimal repro. It can be found in this repository. See readme.md

DZakh commented 4 months ago

Thanks. The validateJsonableSchema just doesn't support recursive schemas. I planned to rewrite it for a long time because of this and another reason, but since there were no recursive users, I postponed it :)

Looks like I have a reason to do so now 😅

For now, you can use serializeToUnknownWith, which doesn't have the validateJsonableSchema check.

DZakh commented 4 months ago

Thank you for reporting and the reproduction. I fixed the error nicely in the commit https://github.com/DZakh/rescript-schema/commit/b86ddea5681ce42a7040ea7bcaf6e4d579096d9a. I want to make a few more changes and release it as a part of the V8 release.

TomiS commented 4 months ago

Very nice. Thanks for addressing this so quickly. I'm on vacation right now but will try out version 8 when it's released - or use the workaround meanwhile.

DZakh commented 4 months ago

Letting you know, that I found a bug with infinit loop when recursive schema fails parsing. I'll release 7.0.2 with a fix asap.

DZakh commented 3 months ago

7.0.2 is published. I recommend you updating

DZakh commented 3 months ago

I released https://github.com/DZakh/rescript-schema/releases/tag/v8.0.0 with a fix 🚀

TomiS commented 3 months ago

I'm happy to confirm the problem indeed seems to have been fixed with 8.0.0. Thanks a lot!