Skip to content

Report container nesting past the recursion limit as IonException - #448

Merged
tgregg merged 3 commits into
amazon-ion:masterfrom
deirdresama:consistent-nesting-error-type
Sep 10, 2026
Merged

tgregg merged 3 commits into
amazon-ion:masterfrom
deirdresama:consistent-nesting-error-type

Conversation

@deirdresama

Copy link
Copy Markdown
Collaborator

Issue #, if available:

Description of changes:

Deeply nested containers raised RecursionError, SystemError, or a misreported
ion-c error code depending on the code path taken. All paths now raise
IonException, with the original error kept as __cause__. Also bumps the
vendored ion-c to v1.1.6.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Comment thread src-python/amazon/ion/simpleion.py Outdated
Comment on lines +529 to +530
# stream directly. A caller advancing it past the recursion limit may see a RecursionError
# instead of an IonException, depending on which depth limit the runtime reaches first.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment accurate? Aren't we ensuring IonException is thrown?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's accurate — this is the one remaining path that surfaces a bare
RecursionError. I checked all 12 public entry points across 3.9–3.13; the other
11 raise IonException everywhere. (This one does too on 3.12+, but only
incidentally: ion-c's max_container_depth is reached first there and raises from
the C side.)

The reason it's uncovered is that this branch hands back the raw C iterator, and
the caller drives it with their own next() calls, outside anything
_translate_recursion_error can wrap. I did try wrapping it in a generator, but
that breaks ionc_write's fast path for re-serializing a stream — it type-checks
for the raw iterator — which showed up as a test_ion_stream failure.

Covering it would mean teaching ionc_write to accept a wrapped iterator as well,
so it's contained but touches the write path for the sake of one lazy read entry
point. Do you want me to close the gap?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gap closed.

@tgregg
tgregg merged commit 9aea992 into amazon-ion:master Sep 10, 2026
20 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