Skip to content

fix: replace panic with Result in LANCE_INITIAL_UPLOAD_SIZE validation#6389

Open
LuciferYang wants to merge 1 commit intolance-format:mainfrom
LuciferYang:fix/object-writer-panic-to-result
Open

fix: replace panic with Result in LANCE_INITIAL_UPLOAD_SIZE validation#6389
LuciferYang wants to merge 1 commit intolance-format:mainfrom
LuciferYang:fix/object-writer-panic-to-result

Conversation

@LuciferYang
Copy link
Copy Markdown
Contributor

Summary

  • Replace panic!() with Result error in initial_upload_size() when LANCE_INITIAL_UPLOAD_SIZE env var is set to an out-of-range value (<5MB or >5GB), preventing process crashes from misconfiguration
  • Store the validated upload_size in the ObjectWriter struct to eliminate repeated OnceLock lookups and avoid any unwrap/expect in the upload path
  • Extract MAX_UPLOAD_PART_SIZE constant for the 5GB upper bound

Motivation

Setting LANCE_INITIAL_UPLOAD_SIZE to a value outside the valid range (less than 5MB or greater than 5GB) crashes the entire process via panic!(). This is a disproportionate response to a configuration error — the caller has no opportunity to handle the failure gracefully. Since ObjectWriter::new() already returns Result<Self>, propagating the error is natural and idiomatic.

What Changed

initial_upload_size(): Return type changed from usize to Result<usize>. Range violations now return Err(Error::invalid_input(...)) instead of panicking. Non-numeric values still silently fall back to the 5MB default, consistent with sibling env vars (LANCE_UPLOAD_CONCURRENCY, LANCE_CONN_RESET_RETRIES).

ObjectWriter struct: Added upload_size: usize field, set once in new() from the validated result. This eliminates repeated OnceLock access in next_part_buffer() and removes the need for any unwrap/expect in the hot path.

next_part_buffer(): Takes upload_size: usize as a parameter instead of calling initial_upload_size() internally.

Behavioral Equivalence

Input Before After
Env not set Returns 5MB default Ok(5MB)
Non-numeric (e.g. "abc") Silent fallback to 5MB Ok(5MB) (unchanged)
Valid integer in range Returns the value Ok(value)
Integer < 5MB panic!() Err(...)
Integer > 5GB panic!() Err(...)

No other behavior changes. All existing callers of ObjectWriter::new() already operate in Result context.

Test plan

  • cargo test -p lance-io -- object_writer — all 4 tests pass
  • cargo clippy -p lance-io -- -D warnings — no warnings
  • cargo fmt -p lance-io -- --check — no formatting issues
  • cargo check --workspace --tests — full workspace compiles

Setting LANCE_INITIAL_UPLOAD_SIZE to an out-of-range value (<5MB or >5GB)
previously crashed the process with panic!(). Now returns an error from
ObjectWriter::new(), letting callers handle it gracefully.

- Change initial_upload_size() return type from usize to Result<usize>
- Cache Result<usize, String> in OnceLock (lance_core::Error is not Clone)
- Store validated upload_size in ObjectWriter struct to avoid repeated
  OnceLock access and eliminate .expect() in next_part_buffer()
- Preserve silent fallback to default for non-numeric values, consistent
  with sibling env vars (LANCE_UPLOAD_CONCURRENCY, LANCE_CONN_RESET_RETRIES)
- Extract MAX_UPLOAD_PART_SIZE constant for the 5GB upper bound
@github-actions github-actions bot added the bug Something isn't working label Apr 2, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 67.64706% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-io/src/object_writer.rs 67.64% 9 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant