Skip to content

Report the attempted depth in generator nesting errors - #1097

Merged
byroot merged 1 commit into
ruby:masterfrom
ydah:fix-generator-nesting-error-depth
Oct 6, 2026
Merged

byroot merged 1 commit into
ruby:masterfrom
ydah:fix-generator-nesting-error-depth

Conversation

@ydah

@ydah ydah commented Oct 6, 2026

Copy link
Copy Markdown
Member

The C and Java generators decrement the depth before reporting it in NestingError, making the reported depth one too small.

require "json"

JSON.generate([[]], max_nesting: 1)
# Before: nesting of 1 is too deep. ...
# After:  nesting of 2 is too deep. ...

Report the attempted depth while preserving depth restoration, same as TruffleRuby. Test arrays, hashes, nonzero initial depths, and State reuse after an error.

Comment thread ext/json/ext/generator/generator.c Outdated
@ydah
ydah force-pushed the fix-generator-nesting-error-depth branch from 63d31f6 to ecdbaeb Compare October 6, 2026 12:08
@byroot
byroot merged commit 37a48ef into ruby:master Oct 6, 2026
42 checks passed
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

Successfully merging this pull request may close these issues.

2 participants