Skip to content
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

refactor(clp_s): delete clp_s::FileReader #711

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aestriplex
Copy link

@aestriplex aestriplex commented Feb 2, 2025

This PR follows the discussion in #664. I removed clp_s/FileReader.hpp and clp_s/FileReader.cpp from the codebase and, consequently, any reference to clp_s/FileReader.hpp.

For the reasons I specified here I have not removed the method clp_s::ZstdDecompressor::open(FileReader&...), but I just updated it to take a reference of clip::FileReader.

Summary by CodeRabbit

  • Refactor
    • Modernised file processing across the application by updating error handling and resource management.
  • Chores
    • Removed deprecated file reading components from tests and build configurations to streamline maintenance.

Copy link
Contributor

coderabbitai bot commented Feb 2, 2025

Walkthrough

This pull request removes the clp_s::FileReader implementation and its associated source files, refactoring code to consistently use the namespaced clp::FileReader. The changes exclude the FileReader files from unit tests and executable builds by updating several CMakeLists files. In addition, refactored source files now handle file operations with updated error code handling and exception management, and the include directives for the obsolete FileReader.hpp have been removed from related headers.

Changes

File(s) Summary
components/core/CMakeLists.txt, components/core/src/clp_s/CMakeLists.txt, components/core/src/clp_s/indexer/CMakeLists.txt Removed FileReader.cpp and FileReader.hpp from build targets and source lists.
components/core/src/clp_s/FileReader.cpp, components/core/src/clp_s/FileReader.hpp Completely removed the clp_s::FileReader implementation and its exception class.
components/core/src/clp_s/ArchiveWriter.cpp, components/core/src/clp_s/CommandLineArguments.cpp, components/core/src/clp_s/Decompressor.hpp, components/core/src/clp_s/ZstdDecompressor.cpp, components/core/src/clp_s/ZstdDecompressor.hpp Updated usage to instantiate and reference clp::FileReader with fully qualified error codes and exception handling, removing manual resource management.
components/core/src/clp_s/JsonParser.hpp, components/core/src/clp_s/SchemaReader.hpp, components/core/src/clp_s/TimestampDictionaryReader.hpp Removed include directives referencing the removed FileReader.hpp.

Sequence Diagram(s)

sequenceDiagram
    participant CMD as CommandLineArguments
    participant FR as clp::FileReader
    participant Log as Logger

    CMD->>FR: Instantiate clp::FileReader(file_path)
    alt Successful file read
        FR-->>CMD: Return file content
    else Read failure (exception)
        FR-->>CMD: Throw OperationFailed exception
        CMD->>Log: Log error via SPDLOG_ERROR
    end
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers

  • LinZhihao-723
  • gibber9809
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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: 0

🧹 Nitpick comments (4)
components/core/src/clp_s/ZstdDecompressor.cpp (1)

291-293: Style: Use false == for consistency with coding guidelines.

While the error handling logic is correct, let's align the condition with the coding guidelines.

-            clp::ErrorCode::ErrorCode_Success != rc && clp::ErrorCode::ErrorCode_EndOfFile != rc)
+            false == (clp::ErrorCode::ErrorCode_Success == rc || clp::ErrorCode::ErrorCode_EndOfFile == rc))
components/core/src/clp_s/CommandLineArguments.cpp (2)

36-47: Consider trimming whitespace for each line read.

When reading lines from the file, you could trim leading and trailing whitespace to guard against accidental spaces or hidden characters. This is a minor refinement that may help ensure cleaner path entries.

 error_code = reader.try_read_to_delimiter('\n', false, false, line);
 if (clp::ErrorCode::ErrorCode_Success != error_code) {
     break;
 }
-if (false == line.empty()) {
-    path_destination.push_back(line);
-}
+{
+    std::string trimmed = clp::trim(line);  // hypothetical trim utility
+    if (false == trimmed.empty()) {
+        path_destination.push_back(trimmed);
+    }
}

54-59: Refine the logged error message for clarity.

The catch block logs a message indicating a failure to “open” the file, but the exception may also occur mid-read. Consider revising the message to reflect that any file read operation could fail.

 SPDLOG_ERROR(
-    "Failed to open file for reading - {} - {}",
+    "File operation failed - {} - {}",
     input_path_list_file_path,
     e.what()
 );
components/core/src/clp_s/ArchiveWriter.cpp (1)

191-191: Consider marking the function as noexcept(false).

The static analysis tool indicates that this function might throw exceptions but isn't marked appropriately.

Apply this change to the function declaration:

-void ArchiveWriter::write_archive_files(
+void ArchiveWriter::write_archive_files(
         FileWriter& archive_writer,
-        std::vector<ArchiveFileInfo> const& files
+        std::vector<ArchiveFileInfo> const& files) noexcept(false)
🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 191-191: Exception thrown in function declared not to throw exceptions.

(throwInNoexceptFunction)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 037cf10 and 1664e19.

📒 Files selected for processing (13)
  • components/core/CMakeLists.txt (0 hunks)
  • components/core/src/clp_s/ArchiveWriter.cpp (1 hunks)
  • components/core/src/clp_s/CMakeLists.txt (0 hunks)
  • components/core/src/clp_s/CommandLineArguments.cpp (2 hunks)
  • components/core/src/clp_s/Decompressor.hpp (2 hunks)
  • components/core/src/clp_s/FileReader.cpp (0 hunks)
  • components/core/src/clp_s/FileReader.hpp (0 hunks)
  • components/core/src/clp_s/JsonParser.hpp (0 hunks)
  • components/core/src/clp_s/SchemaReader.hpp (0 hunks)
  • components/core/src/clp_s/TimestampDictionaryReader.hpp (0 hunks)
  • components/core/src/clp_s/ZstdDecompressor.cpp (3 hunks)
  • components/core/src/clp_s/ZstdDecompressor.hpp (3 hunks)
  • components/core/src/clp_s/indexer/CMakeLists.txt (0 hunks)
💤 Files with no reviewable changes (8)
  • components/core/src/clp_s/SchemaReader.hpp
  • components/core/src/clp_s/TimestampDictionaryReader.hpp
  • components/core/src/clp_s/JsonParser.hpp
  • components/core/src/clp_s/indexer/CMakeLists.txt
  • components/core/src/clp_s/FileReader.hpp
  • components/core/src/clp_s/CMakeLists.txt
  • components/core/src/clp_s/FileReader.cpp
  • components/core/CMakeLists.txt
🧰 Additional context used
📓 Path-based instructions (5)
components/core/src/clp_s/ArchiveWriter.cpp (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/core/src/clp_s/Decompressor.hpp (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/core/src/clp_s/ZstdDecompressor.hpp (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/core/src/clp_s/ZstdDecompressor.cpp (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/core/src/clp_s/CommandLineArguments.cpp (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

🪛 Cppcheck (2.10-2)
components/core/src/clp_s/ArchiveWriter.cpp

[error] 191-191: Exception thrown in function declared not to throw exceptions.

(throwInNoexceptFunction)

🔇 Additional comments (11)
components/core/src/clp_s/ZstdDecompressor.hpp (3)

12-12: LGTM! Include directive added for the new namespace.

The include directive for clp::FileReader is correctly added, aligning with the PR's objective to remove clp_s::FileReader.


45-45: LGTM! Method signature updated to use clp::FileReader.

The method signature has been correctly updated to use clp::FileReader, as mentioned in the PR objectives.


134-134: LGTM! Member variable type updated to use clp::FileReader.

The member variable type has been correctly updated to use clp::FileReader, maintaining consistency with the method signature change.

components/core/src/clp_s/ZstdDecompressor.cpp (3)

69-78: LGTM! Error handling improvements.

The changes improve clarity by using fully qualified error codes and ensure type safety through explicit casting.


167-167: LGTM! Signature update aligns with PR objectives.

The change from FileReader to clp::FileReader is consistent with the PR's goal of removing clp_s::FileReader.


Line range hint 303-307: LGTM! Consistent error handling and style.

The error handling for ClpReader follows the same pattern as FileReader and adheres to the coding guidelines.

components/core/src/clp_s/CommandLineArguments.cpp (2)

12-12: Header inclusion looks correct.

Replacing the local FileReader header with FileReader.hpp from the clp namespace aligns with the objective of removing the old file reading mechanism in clp_s.


50-53: Confirm error-handling for unexpected file read errors.

The code returns false for any error code that is not ErrorCode_EndOfFile. Ensure that this behaviour covers partial readings or other scenarios where incomplete results might be acceptable.

components/core/src/clp_s/ArchiveWriter.cpp (1)

182-191: LGTM! The changes align with the PR objectives.

The code correctly transitions from clp_s::FileReader to clp::FileReader and properly handles error codes with the new namespace. The removal of explicit close() suggests proper RAII usage.

Let's verify that all FileReader usages have been updated consistently:

✅ Verification successful

FileReader usage is consistently updated.
All instances of clp_s::FileReader have been removed, and the code now uniformly uses clp::FileReader. The RAII-based error handling appears in line with the intended design change.

  • No remaining references to clp_s::FileReader were found.
  • All FileReader implementations are correctly namespaced.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all FileReader usages have been updated to use clp::FileReader
# Test: Search for any remaining references to clp_s::FileReader
rg -l "clp_s::FileReader"

# Test: Verify all FileReader usages are properly namespaced
ast-grep --pattern 'FileReader'

Length of output: 858

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 191-191: Exception thrown in function declared not to throw exceptions.

(throwInNoexceptFunction)

components/core/src/clp_s/Decompressor.hpp (2)

8-8: LGTM! Include directive updated correctly.

The include directive has been properly updated to use the FileReader from the clp namespace, which aligns with the PR objective of removing clp_s::FileReader.


52-52: LGTM! Method signature updated correctly.

The parameter type has been properly updated to use clp::FileReader. Since this is a pure virtual method, we should verify that all derived classes have been updated accordingly.

Let's verify that all derived classes have been updated to use clp::FileReader:

✅ Verification successful

Approval Notice: Decompressor Interface and Its Derived Classes Updated Correctly

The change to use clp::FileReader for the open method’s parameter is correctly applied in clp_s/Decompressor.hpp. Inspection of derived classes (e.g. in ZstdDecompressor) confirms that the override using clp::FileReader is present. There are additional overloads (e.g. one taking clp::ReaderInterface) but they do not conflict with the intended update.

  • clp_s/Decompressor.hpp now declares:
    • virtual void open(clp::FileReader& file_reader, size_t file_read_buffer_capacity) = 0;
  • Derived classes, such as ZstdDecompressor, correctly override the open method with a matching signature.

LGTM!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all derived classes of Decompressor and verify their open method signatures

# Find all derived classes of Decompressor
ast-grep --pattern 'class $_ : $$$public $$$Decompressor$$$'

# Search for any remaining references to FileReader without the clp:: namespace
rg -g '*.{cpp,hpp}' --no-heading 'FileReader[^:]' -A 2 -B 2

Length of output: 59571

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.

1 participant