Skip to content

fix: ensure panic safety #1212

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

Merged
merged 9 commits into from
Feb 27, 2025
Merged

fix: ensure panic safety #1212

merged 9 commits into from
Feb 27, 2025

Conversation

de-sh
Copy link
Contributor

@de-sh de-sh commented Feb 25, 2025

Fixes #XXXX.

Description

Don't panic when file metadata can't be extracted because file doesn't exist


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling to ensure smoother file processing and reduce unexpected interruptions. Users benefit from a more resilient system that gracefully handles issues during file data retrieval.
  • Refactor

    • Streamlined logging messages and standardized internal reporting labels for consistency and clarity, enhancing overall operational stability without affecting visible functionality.
    • Introduced a new constant for arrow file extensions to standardize file handling.
    • Enhanced clarity in method parameters for better understanding of expected inputs.

Copy link
Contributor

coderabbitai bot commented Feb 25, 2025

Walkthrough

This pull request introduces a new constant ARROW_FILE_EXTENSION with the value "arrows" in the mod.rs module to designate arrow file extensions. In the streams.rs module, the constant's declaration has been moved to the import statement, enhancing its visibility. Additionally, error handling has been improved by replacing unwrap() calls with expect() and match statements, enhancing robustness. Logging has been updated for clarity, and the metrics label for arrow files now uses the new constant, standardizing its usage without altering core functionality.

Changes

File(s) Change Summary
src/parseable/mod.rs Added constant ARROW_FILE_EXTENSION set to "arrows".
src/parseable/streams.rs Moved constant import; replaced unwrap() with expect() for metadata retrieval; updated logging format; used match for file size retrieval; updated metrics label to use the new constant.
src/parseable/staging/reader.rs Updated method signature from try_new(files: &[PathBuf]) to try_new(file_paths: &[PathBuf]); improved error handling and logging for file access.
src/storage/object_storage.rs Simplified error handling and deserialization logic in get_manifest method; used ? operator for error propagation and streamlined specific error handling.

Possibly related PRs

  • feat: merge finish .arrows and convert to .parquet #1200: The changes in the main PR, which involve adding a constant for the file extension of arrow files, are related to the modifications in the retrieved PR that involve handling the conversion of .arrows files, as both PRs deal with the same file type and its processing.
  • fix: staging files count in metrics #1207: The changes in the main PR, which involve adding a constant for the Arrow file extension, are related to the modifications in the retrieved PR that involve calculating metrics for Arrow files, as both PRs reference the same constant ARROW_FILE_EXTENSION in their implementations.

Suggested labels

for next release

Suggested reviewers

  • nikhilsinhaparseable

Poem

Hop along the code trail, crisp and clear,
I’m a rabbit with constants that now appear.
With logging neat and errors well-prepared,
My burrow of code is joyfully shared.
Carrots and bytes, a merry mix so dear!
🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aad96b0 and de2ebff.

📒 Files selected for processing (1)
  • src/parseable/staging/reader.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/parseable/staging/reader.rs
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: coverage

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/parseable/streams.rs (1)

487-488: Improved error messaging but still has panic potential

Replacing unwrap() with expect("File was just created") provides better context when an error occurs. However, this still has the potential to panic.

Consider using a match pattern similar to what you implemented on lines 504-513 to fully eliminate panic potential in all cases.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 649c000 and c4b67e9.

📒 Files selected for processing (2)
  • src/parseable/mod.rs (1 hunks)
  • src/parseable/streams.rs (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/parseable/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
🔇 Additional comments (3)
src/parseable/streams.rs (3)

64-64: Good improvement in constant usage

Using the imported constant ARROW_FILE_EXTENSION instead of a local definition enhances code maintainability and consistency across the codebase.


491-492: Improved logging format

The updated format string makes the log message more concise and easier to read.


519-519: Enhanced consistency using a constant

Using the imported constant ARROW_FILE_EXTENSION instead of a hardcoded string ensures consistency across metrics labels. If the file extension ever changes, it will only need to be updated in one place.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/parseable/staging/reader.rs (1)

85-102: Improved panic safety and error handling.

The method has been refactored to handle file operations more safely, preventing potential panics. Key improvements include:

  1. Better parameter naming (file_paths instead of files)
  2. Using pattern matching with let Ok(file) = File::open(&path) else {...} instead of unwrapping
  3. Appropriate logging levels (warning for file open failures, error for invalid files)
  4. Explicitly skipping problematic files with continue

Consider enhancing the warning message to include the actual error details, not just the path:

- warn!("Error when trying to read file: {path:?}");
+ warn!("Error when trying to read file {path:?}: {err}");

This would require capturing the error in the pattern matching:

- let Ok(file) = File::open(&path) else {
+ let Ok(file) = File::open(&path).map_err(|err| {
+     warn!("Error when trying to read file {path:?}: {err}");
+ }) else {
-     warn!("Error when trying to read file: {path:?}");
      continue;
  };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e41597 and ff9cddf.

📒 Files selected for processing (1)
  • src/parseable/staging/reader.rs (2 hunks)
🔇 Additional comments (3)
src/parseable/staging/reader.rs (3)

33-33: Enhanced logging with appropriate severity levels.

Adding the warn import allows using different logging levels based on error severity, which is a good practice for more granular log analysis.


93-96: Consistent error handling pattern.

The error handling pattern applied to file opening is consistently applied to the reverse reader creation as well, maintaining a uniform approach to error handling throughout the method.


87-91:

❓ Verification inconclusive

Verify the impact on file processing metrics.

The change from error logging to warning for file open failures might affect how many files are reported as failed in metrics/monitoring. Ensure this doesn't hide important issues that should be tracked.


🏁 Script executed:

#!/bin/bash
# Look for any metrics or monitoring code that might be affected by the logging change
rg -A 3 -B 3 "error.*trying to read file" --type rust
rg -A 3 -B 3 "failed.*files" --type rust
rg -A 3 -B 3 "file.*metrics" --type rust

Length of output: 697


Action: Verify Monitoring Impact from Logging Level Change

The downgrade from error to warning when a file open fails in src/parseable/staging/reader.rs might reduce the signal used by our monitoring to flag failed file reads. While a scan of the codebase (notably in src/parseable/streams.rs) shows that metrics for staging files are being explicitly checked—e.g., via metrics::STAGING_FILES—it’s unclear whether file open failures in the reader are correlated with these metrics. Please verify that file read errors still contribute to tracking failures in our metrics pipeline. Consider whether an explicit metric counter should be incremented alongside logging rather than relying solely on log severity for monitoring.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/storage/object_storage.rs (1)

464-470: Improved error handling with cleaner, more idiomatic code

The refactoring of the get_manifest method simplifies the error handling by using the ? operator for deserialization errors instead of a nested match statement. This change aligns perfectly with the PR objective of ensuring panic safety, as it properly propagates any deserialization errors rather than potentially causing a panic.

The code is now more concise and follows Rust's idiomatic error handling patterns, making it easier to read and maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3122c01 and faacd19.

📒 Files selected for processing (1)
  • src/storage/object_storage.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: coverage
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 26, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 26, 2025
Signed-off-by: Devdutt Shenoi <[email protected]>
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants