fix: improve error handling for environment variable parsing#5560
Merged
yanghua merged 6 commits intolance-format:mainfrom Jan 16, 2026
Merged
Conversation
aeb086d to
9f91118
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
24657a1 to
66eab2e
Compare
yanghua
reviewed
Dec 26, 2025
| Ok(value) => Some(value), | ||
| Err(e) => { | ||
| log::warn!( | ||
| "Failed to parse {}='{}': {}. {}", |
Collaborator
There was a problem hiding this comment.
Failed to parse the environment variable {}='{}': {}, the default value is: {}.
| pub(crate) const BATCH_SIZE_FALLBACK: usize = 8192; | ||
|
|
||
| /// Parse an environment variable as a specific type, logging a warning on parse failure. | ||
| fn parse_env_var<T: std::str::FromStr>(env_var_name: &str, default_hint: &str) -> Option<T> |
Collaborator
There was a problem hiding this comment.
default_hint -> default_val?
yanghua
reviewed
Dec 26, 2025
| std::env::var("LANCE_DEFAULT_BATCH_SIZE") | ||
| .map(|val| Some(val.parse().unwrap())) | ||
| .unwrap_or(None) | ||
| parse_env_var("LANCE_DEFAULT_BATCH_SIZE", "Using default.") |
Collaborator
There was a problem hiding this comment.
IMO, here the second parameter we can just pass the string representing the value. WDYT?
yanghua
reviewed
Dec 26, 2025
| .unwrap_or(None) | ||
| }); | ||
| pub static DEFAULT_FRAGMENT_READAHEAD: LazyLock<Option<usize>> = | ||
| LazyLock::new(|| parse_env_var("LANCE_DEFAULT_FRAGMENT_READAHEAD", "Using default.")); |
9794d17 to
e2640bd
Compare
yanghua
reviewed
Jan 16, 2026
| std::env::var("LANCE_DEFAULT_BATCH_SIZE") | ||
| .map(|val| Some(val.parse().unwrap())) | ||
| .unwrap_or(None) | ||
| parse_env_var("LANCE_DEFAULT_BATCH_SIZE", "8192") |
Collaborator
There was a problem hiding this comment.
8192 -> &BATCH_SIZE_FALLBACK.to_string()
Can we try it?
yanghua
approved these changes
Jan 16, 2026
Collaborator
yanghua
left a comment
There was a problem hiding this comment.
LGTM! Thanks for your patience!
jackye1995
pushed a commit
to jackye1995/lance
that referenced
this pull request
Jan 21, 2026
…nce-format#5560) Replace unwrap() calls with proper error handling in environment variable parsing functions to prevent panics when invalid values are provided. Changes: - get_default_batch_size(): Handle invalid LANCE_DEFAULT_BATCH_SIZE values - DEFAULT_FRAGMENT_READAHEAD: Handle invalid LANCE_DEFAULT_FRAGMENT_READAHEAD values - DEFAULT_XTR_OVERFETCH: Handle invalid LANCE_XTR_OVERFETCH values - DEFAULT_IO_BUFFER_SIZE: Handle invalid LANCE_DEFAULT_IO_BUFFER_SIZE values When parsing fails, the functions now: 1. Log a warning message with the invalid value and error 2. Fall back to default values gracefully 3. Prevent application crashes due to configuration errors Added test_env_var_parsing() to verify the new error handling behavior.
vivek-bharathan
pushed a commit
to vivek-bharathan/lance
that referenced
this pull request
Feb 2, 2026
…nce-format#5560) Replace unwrap() calls with proper error handling in environment variable parsing functions to prevent panics when invalid values are provided. Changes: - get_default_batch_size(): Handle invalid LANCE_DEFAULT_BATCH_SIZE values - DEFAULT_FRAGMENT_READAHEAD: Handle invalid LANCE_DEFAULT_FRAGMENT_READAHEAD values - DEFAULT_XTR_OVERFETCH: Handle invalid LANCE_XTR_OVERFETCH values - DEFAULT_IO_BUFFER_SIZE: Handle invalid LANCE_DEFAULT_IO_BUFFER_SIZE values When parsing fails, the functions now: 1. Log a warning message with the invalid value and error 2. Fall back to default values gracefully 3. Prevent application crashes due to configuration errors Added test_env_var_parsing() to verify the new error handling behavior.
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.
Replace unwrap() calls with proper error handling in environment variable parsing functions to prevent panics when invalid values are provided.
Changes:
When parsing fails, the functions now:
Added test_env_var_parsing() to verify the new error handling behavior.