-
Notifications
You must be signed in to change notification settings - Fork 510
fix: improve error handling for environment variable parsing #5560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: improve error handling for environment variable parsing #5560
Conversation
aeb086d to
9f91118
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
9f91118 to
24657a1
Compare
24657a1 to
66eab2e
Compare
yanghua
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments.
rust/lance/src/dataset/scanner.rs
Outdated
| Ok(value) => Some(value), | ||
| Err(e) => { | ||
| log::warn!( | ||
| "Failed to parse {}='{}': {}. {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed to parse the environment variable {}='{}': {}, the default value is: {}.
rust/lance/src/dataset/scanner.rs
Outdated
| 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default_hint -> default_val?
| 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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, here the second parameter we can just pass the string representing the value. WDYT?
| .unwrap_or(None) | ||
| }); | ||
| pub static DEFAULT_FRAGMENT_READAHEAD: LazyLock<Option<usize>> = | ||
| LazyLock::new(|| parse_env_var("LANCE_DEFAULT_FRAGMENT_READAHEAD", "Using default.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
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.