feat(arrow-buffer): add OutOfBoundsError and fallible Buffer slicing - #10737
Draft
emilk wants to merge 1 commit into
Draft
feat(arrow-buffer): add OutOfBoundsError and fallible Buffer slicing#10737emilk wants to merge 1 commit into
OutOfBoundsError and fallible Buffer slicing#10737emilk wants to merge 1 commit into
Conversation
`Buffer::slice`, `advance` and `slice_with_length` panic when asked for a range they do not hold. Add `OutOfBoundsError` and a `try_` variant for each: * `Buffer::try_slice` * `Buffer::try_advance` (leaves the buffer unchanged on failure) * `Buffer::try_slice_with_length` The panicking versions delegate to the fallible ones and keep their existing panic messages, which several crates assert on in tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Buffer::slice,Buffer::advanceandBuffer::slice_with_lengthpanic when asked for a range the buffer does not hold, and there is no way to ask without risking the panic. They are also the reasonScalarBuffer::newcannot get atry_newyet: two of its four panic causes come from these functions.arrow-bufferdoes not depend onarrow-schema, so it has noArrowError. It uses one small error type per concern instead (MutableBufferError,ParseI256Error), so this adds one more in that style.What changes are included in this PR?
OutOfBoundsError(Copy, no allocation) and atry_variant for each of the three:Buffer::try_sliceBuffer::try_advance, which leaves the buffer unchanged when it failsBuffer::try_slice_with_lengthThe panicking versions delegate to the fallible ones and keep their existing panic messages verbatim, since
arrow-arrayand others assert on them.Buffer::bit_sliceis left alone: its panic comes from two different paths and deserves its own change.Note this adds
arrow-buffer/src/error.rs, the same file as #10736. Whichever lands first, I will rebase the other.Are these changes tested?
Yes, new tests for each error path, including
offset + lengthoverflowingusize. The existingshould_panictests are untouched, which is what pins the panic messages.Are there any user-facing changes?
New public API only, no breaking changes.