Conversation
- Replace unwrap() calls with expect() containing descriptive error messages - Add nanosecond units and formatting to histogram/timer metric output
Summary of ChangesHello @harryscholes, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the testability and robustness of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request replaces .unwrap() calls with .expect(), which is a good step for improving panic messages. However, for a library function that returns a Result, panicking is often not the desired behavior. My review includes suggestions to propagate errors using the ? operator instead, which will make the code more robust. This is particularly critical within a map closure where a panic could crash the entire application. I've also noted the formatting improvements to the logging output, which are a welcome change.
| let id_utf8_value = id_scalar | ||
| .as_utf8() | ||
| .value() | ||
| .expect("id should be a valid UTF8 value"); |
There was a problem hiding this comment.
While using expect is an improvement over unwrap, it will still cause a panic on failure. This is especially problematic inside a map closure. The idiomatic Rust approach for error handling here is to have the closure return a Result, and then use collect() to gather the results into a Result<Vec<_>, _>. This allows using the ? operator for clean error propagation and prevents the application from crashing.
This would require a refactoring of the surrounding map and collect calls. Here's an example of how it could look:
let mut results = (0..s.len())
.map(|i| -> Result<_, Box<dyn std::error::Error>> {
// ...
let id_utf8_value = id_scalar
.as_utf8()
.value()
.ok_or("id should be a valid UTF8 value")?;
// ... and for other `expect` calls
Ok(ResultElement { ... })
})
.collect::<Result<Vec<_>, _>>()?;This change is highly recommended for robust error handling and should be applied to all expect calls within this map block.
| let row_idx = row_idx | ||
| .as_primitive() | ||
| .typed_value() | ||
| .expect("row_idx should be a valid u64 value"); |
There was a problem hiding this comment.
Using expect will cause the program to panic if the Option is None. Since this function returns a Result, it's better to propagate the error using the ? operator. This allows the caller to handle the error gracefully instead of crashing the application.
| let row_idx = row_idx | |
| .as_primitive() | |
| .typed_value() | |
| .expect("row_idx should be a valid u64 value"); | |
| let row_idx = row_idx | |
| .as_primitive() | |
| .typed_value() | |
| .ok_or("row_idx should be a valid u64 value")?; |
| let id = id | ||
| .as_utf8() | ||
| .value() | ||
| .expect("id should be a valid UTF8 value"); |
There was a problem hiding this comment.
Similar to the previous comment, using expect here can cause a panic. It's better to propagate the error using ? to allow for graceful error handling.
| let id = id | |
| .as_utf8() | |
| .value() | |
| .expect("id should be a valid UTF8 value"); | |
| let id = id | |
| .as_utf8() | |
| .value() | |
| .ok_or("id should be a valid UTF8 value")?; |
| let row_idx = row_idx | ||
| .as_primitive() | ||
| .typed_value() | ||
| .expect("row_idx should be a valid u64 value"); |
There was a problem hiding this comment.
Using expect will cause a panic on None. Since this function returns a Result, it's better to propagate errors using ?.
| let row_idx = row_idx | |
| .as_primitive() | |
| .typed_value() | |
| .expect("row_idx should be a valid u64 value"); | |
| let row_idx = row_idx | |
| .as_primitive() | |
| .typed_value() | |
| .ok_or("row_idx should be a valid u64 value")?; |
| let id = id | ||
| .as_utf8() | ||
| .value() | ||
| .expect("id should be a valid UTF8 value"); |
There was a problem hiding this comment.
No description provided.