Skip to content

fix: stop try_ functions from panicking - #10730

Open
emilk wants to merge 3 commits into
apache:mainfrom
emilk:emilk/fix-panicking-try-fns
Open

fix: stop try_ functions from panicking#10730
emilk wants to merge 3 commits into
apache:mainfrom
emilk:emilk/fix-panicking-try-fns

Conversation

@emilk

@emilk emilk commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

A try_ function that returns a Result but still panics is the worst of both worlds: the caller writes error handling and gets a panic anyway.

What changes are included in this PR?

  • FFI_ArrowSchema::try_new: an interior nul byte in format was an unwrap, and the error path leaked the children.
  • MutableArrayData::try_extend: validates the array index and the start..end range, which used to underflow.
  • MutableArrayData::try_extend_nulls: errors instead of panicking when there is no null buffer.
  • VariantArray::try_value: errors on an out of bounds index, and on conflicting value/typed_value.

MutableBuffer::try_from_trusted_len_iter still panics on a bad size_hint: that is part of its unsafe contract, and the docs now say so.

Are these changes tested?

Yes, a test per error path.

Are there any user-facing changes?

Panics turn into errors. MutableArrayData::extend/extend_nulls still panic as before.

@emilk
emilk marked this pull request as ready for review August 18, 2026 14:16

@Rich-T-kid Rich-T-kid left a comment

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.

looks mostly good to me but I have a few comments

Comment thread arrow-schema/src/ffi.rs
Comment thread parquet-variant-compute/src/variant_array.rs Outdated
Comment thread arrow-data/src/transform/mod.rs Outdated
Comment thread arrow-data/src/transform/mod.rs Outdated
Comment thread arrow-arith/src/arity.rs Outdated
NullBuffer::union(a.logical_nulls().as_ref(), b.logical_nulls().as_ref()).unwrap();
// `null_count` is a physical count, so it can be non-zero for arrays that
// have no logical nulls at all:
let Some(nulls) = NullBuffer::union(a.logical_nulls().as_ref(), b.logical_nulls().as_ref())

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.

do we have a reproduction for this? im struggling to conceptualize a case where we physically have nulls but logically dont have nulls 🤔

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.

One example is RunArray… except the if above was wrong, and was checking null_count instead of is_nullable. Fixed in 97f3028

@emilk emilk Aug 19, 2026

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.

This is an actual bug fix now btw - test_try_binary_run_array_logical_nulls fails on main with

  assertion `left == right` failed
    left:  [11, 1, 31]
    right: [11, null, 31]

should I split out the bug fix into its own PR?

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.

yeah we should split this into a separate PR

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.

@Jefffrey Jefffrey added the bug label Aug 19, 2026
@emilk
emilk force-pushed the emilk/fix-panicking-try-fns branch 2 times, most recently from 4659507 to 97f3028 Compare August 19, 2026 03:16
@Jefffrey

Copy link
Copy Markdown
Contributor

run benchmark mutable_array

@adriangbot

This comment was marked as duplicate.

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

Comparing emilk/fix-panicking-try-fns (97f3028) to bb1e6cd (merge-base) diff

Run configuration
run benchmark mutable_array
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                     emilk_fix-panicking-try-fns            main
-----                     ---------------------------            ----
mutable str 1024          1.00     43.8±0.31ms        ? ?/sec    1.34     58.8±1.88ms        ? ?/sec
mutable str nulls 1024    1.00     14.2±0.11ms        ? ?/sec    1.01     14.2±0.15ms        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 25.0s
Peak memory 136.3 MiB
Avg memory 56.6 MiB
CPU user 3.5s
CPU sys 15.3s
Peak spill 0 B

branch

Metric Value
Wall time 25.0s
Peak memory 149.1 MiB
Avg memory 83.6 MiB
CPU user 4.4s
CPU sys 18.6s
Peak spill 0 B

File an issue against this benchmark runner

emilk and others added 3 commits August 19, 2026 08:38
A `try_` function that returns a `Result` but still panics is the worst of
both worlds. Turn those panics into errors:

* `FFI_ArrowSchema::try_new`: an interior nul byte in `format` was an
  `unwrap`. It now returns `ArrowError::CDataInterface`, and the format is
  converted before the children are leaked, so the error path no longer
  leaks memory.
* `MutableArrayData::try_extend`: validate the source array index and the
  `start..end` range. `end < start` used to underflow.
* `MutableArrayData::try_extend_nulls`: return an error instead of panicking
  when the builder has no null buffer.
* `VariantArray::try_value`: return an error for an out of bounds index and
  for a row with conflicting `value` and `typed_value`.
* `try_binary`: `NullBuffer::union` returns `None` when neither input has
  logical nulls, which is possible even when `null_count() > 0`. Fall back to
  the no-nulls path instead of unwrapping.

`MutableBuffer::try_from_trusted_len_iter` still panics on a bad `size_hint`:
that is part of its `unsafe` contract, and the docs now say so.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: hovering the function should show the reasons, without
having to open the `try_` version's docs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback. `FFI_ArrowSchema::try_new` had the reason in prose,
`try_binary` used `# Error`, and `try_from_trusted_len_iter` did not say
what its `Err` meant.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@emilk

emilk commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants