Skip to content

docs: add # Panics sections across the workspace - #10656

Open
emilk wants to merge 4 commits into
apache:mainfrom
emilk:emilk/document-panics
Open

docs: add # Panics sections across the workspace#10656
emilk wants to merge 4 commits into
apache:mainfrom
emilk:emilk/document-panics

Conversation

@emilk

@emilk emilk commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

As a user, I want to avoid panics, so panics should be documented.

In a future PR I will look at all functions with # Panics and make sure they have a try_ variant that instead returns a Result.

What changes are included in this PR?

Docs only, no code changes.

Adds # Panics to public functions that panic on bad arguments or bad state.

Also normalizes # Panic to # Panics and converts loose "this will panic if ..." prose into proper sections.

Are these changes tested?

No new tests; docs only.

Are there any user-facing changes?

Better docs!

Sweep every crate for public functions that panic on bad arguments or
bad state and document them:

- arrow-buffer: `NullBuffer::{is_valid, is_null, slice, expand}`,
  `BooleanBuffer::slice`, `ScalarBuffer::slice`, `OffsetBuffer`,
  `Buffer::bit_slice`, `bit_util`, `bit_mask::set_bits`, bitmap builders,
  `i256` division and logarithms
- arrow-array: `Array::{is_null, is_valid, slice}` and every inherent
  `slice`, index accessors (`value_length`, `value_size`, `value_offset`,
  `column`, `key`, `value_as_*`), `cast.rs` downcast helpers, builder
  `finish`/`finish_cloned`, `make_builder`, deprecated `Date32Type`
  interval helpers, `div_wrapping`/`mod_wrapping`
- arrow-data, arrow-schema: FFI schema accessors
- arrow-ord, arrow-row, arrow-cast: `compare_byte_view`,
  `Rows::{push, row}`, `b64_encode`
- arrow: bench and test helpers that assert on their arguments
- parquet: `ByteArray` accessors, `Sbbf::new_with_num_of_bytes`,
  `byte_range`, `with_range`, truncate-length setters, typed column
  reader/writer casts, `schema::types` accessors
- parquet-variant: infallible constructors, `get`, `iter`, `get_entry`,
  `ObjectBuilder::{new_object, new_list}`

Also normalize nine `# Panic` headers to `# Panics` so they are found by
a search, and convert loose "this will panic if ..." prose into proper
sections.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@emilk emilk changed the title docs: add missing # Panics sections across the workspace docs: add # Panics sections across the workspace Aug 12, 2026
@emilk
emilk marked this pull request as ready for review August 12, 2026 11:34

@timsaucer timsaucer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The only other thing I mentioned when we chatted was the inconsistent use of an extra line between the # Panics and the text about the panic, but I understand that it's trying to keep each file self consistent.

The issues below were flagged by an agent but I verified each one.

Comment thread arrow-buffer/src/builder/boolean.rs Outdated
Comment thread parquet/src/bloom_filter/mod.rs Outdated
Comment thread arrow-schema/src/ffi.rs Outdated
Comment thread arrow-array/src/array/byte_array.rs Outdated
Comment thread arrow-array/src/array/mod.rs Outdated
- Use concrete index expressions in the bitmap builders instead of prose
- Drop two unreachable claims: `optimal_num_of_bytes` always returns a
  multiple of the block size, and a non-negative `i32` always fits `usize`
- `from_iter_values` also panics on offset overflow
- State the `is_null`/`is_valid` contract as `index >= self.len()` and mark
  the non-checking path as not guaranteed, so it stays fixable

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
{
let iter = iter.into_iter();
let (_, data_len) = iter.size_hint();
let data_len = data_len.expect("Iterator must be sized"); // panic if no upper bound.

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.

this is interesting; it might actually be a bug. i dont see why we should restrict to requiring an upper bound especially as its not guaranteed an iter will yield only up to upper bound

It is not enforced that an iterator implementation yields the declared number of elements. A buggy iterator may yield less than the lower bound or more than the upper bound of elements.

perhaps in a followup/separate PR we can remove this expect, to have one less panic in our codebase

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree - but I didn't want to change behavior in this PR

Comment thread arrow-array/src/builder/generic_bytes_view_builder.rs Outdated
Comment thread arrow-array/src/cast.rs Outdated
@Jefffrey Jefffrey added the documentation Improvements or additions to documentation label Aug 13, 2026
@emilk
emilk force-pushed the emilk/document-panics branch from 62b4823 to 5d1e2b1 Compare August 13, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-array arrow-buffer arrow-cast arrow-data arrow-ord arrow-row arrow-schema documentation Improvements or additions to documentation parquet Changes to the parquet crate parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants