Skip to content

refactor(io_interface): Change ReaderInterface to return ErrorCodes instead of throwing exceptions; address clang-tidy violations in ReaderInterface. #49

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 3 commits into from
Apr 2, 2025

Conversation

Bill-hbrhbr
Copy link
Collaborator

@Bill-hbrhbr Bill-hbrhbr commented Mar 29, 2025

Description

  • Consolidate try_do_something() and do_something() functions into a single implementation in the API.

    • Remove OperationFailed and all exception handlings, since users should interact with ystdlib-cpp exclusively via the ErrorCode system.
    • Ensure all functions return an ErrorCode instead of throwing exceptions.
    • Eliminate eof_possible flags from applicable functions and return EOF-related error codes directly.
    • Update function docstrings to comply with the latest C++ coding guidelines.
  • Remove all NOLINT comments and apply clang-tidy fixes on the refactored files, except for Provide a well-defined off_t type across different operating system platforms. #50

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Refactor. No unit tests added.

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor
    • Streamlined data reading routines by consolidating redundant operations and simplifying error handling for improved reliability and consistency.
    • Updated method signatures to enhance clarity and modern C++ practices, including the introduction of [[nodiscard]] attributes.
  • Chore
    • Enhanced resource management and updated control mechanisms, ensuring efficient operations and promoting overall system stability.

Copy link

coderabbitai bot commented Mar 29, 2025

Walkthrough

The pull request refactors the ReaderInterface class by renaming methods (changing try_read_* to read_*) and updating their signatures to use an auto return type with a trailing return type specification. The internal logic is streamlined by removing the separate read method and directly integrating error handling. In the header, the class interface is updated with a default constructor, deleted copy semantics, and added move semantics. Method signatures now use [[nodiscard]] and include revised approaches for seeking and position retrieval.

Changes

Files Change Summary
src/.../ReaderInterface.cpp Renamed methods (try_read_to_delimiterread_to_delimiter, try_read_exact_lengthread_exact_length, try_read_stringread_string); removed the redundant read method; streamlined and simplified error handling.
src/.../ReaderInterface.hpp Updated interface declarations: added default constructor, deleted copy constructor/assignment, added move constructor/assignment; updated method signatures to return ErrorCode with [[nodiscard]]; replaced seek_from_begin with seek_from_current and modified get_pos.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Reader
    Client->>Reader: read_string(str_length, str)
    Reader->>Reader: read_exact_length(buf, num_bytes)
    Reader-->>Client: ErrorCode
Loading
sequenceDiagram
    participant Client
    participant Reader
    Client->>Reader: read_to_delimiter(delim, keep_delimiter, append, str)
    Reader-->>Client: ErrorCode
Loading

Possibly related PRs

Suggested reviewers

  • davidlion
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

@Bill-hbrhbr Bill-hbrhbr changed the title refactor(io_interface): Remove OperationFailed and have all functions return ErrorCode in the ReaderInterface class. refactor(io_interface): Unify ReaderInterface error handling using ErrorCode and remove exception throwing; run clang-tidy on changed files. Mar 29, 2025
@Bill-hbrhbr Bill-hbrhbr marked this pull request as ready for review March 29, 2025 03:28
@Bill-hbrhbr Bill-hbrhbr requested a review from a team as a code owner March 29, 2025 03:28
Copy link

@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 (3)
src/ystdlib/io_interface/ReaderInterface.hpp (3)

4-6: TODO and NOLINTNEXTLINE present despite PR objective to remove them

The PR objectives mentioned removing all NOLINT comments, but there's still a NOLINTNEXTLINE comment here. Consider addressing the TODO item in a separate PR or updating the current PR's objectives to clarify that some TODOs and NOLINT comments will remain.


48-49: Method formatting inconsistency

The read_to_delimiter method declaration spans two lines with a different formatting style than other methods. Consider making the formatting consistent across all methods.

-    [[nodiscard]] virtual auto
-    read_to_delimiter(char delim, bool keep_delimiter, bool append, std::string& str) -> ErrorCode;
+    [[nodiscard]] virtual auto read_to_delimiter(char delim, bool keep_delimiter, bool append, std::string& str) 
+            -> ErrorCode;

80-82: TODO and NOLINTNEXTLINE still present

Similar to the earlier TODO, there's another one here with a NOLINTNEXTLINE comment. Consider addressing this in a separate PR or updating the current PR objectives.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b8d41db and b86ee54.

📒 Files selected for processing (1)
  • src/ystdlib/io_interface/ReaderInterface.hpp (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

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

  • src/ystdlib/io_interface/ReaderInterface.hpp
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (macos-15)
  • GitHub Check: lint-check (ubuntu-24.04)
🔇 Additional comments (8)
src/ystdlib/io_interface/ReaderInterface.hpp (8)

16-25: Good addition of special member functions with proper semantics

The class now properly defines its special member functions following the rule of five. Deleting copy operations and enabling move operations is a good practice for resource-owning interfaces, especially ones that might be used in containers or transferred between objects.


31-39: Improved method signature with [[nodiscard]] and error code return

The method signature change from returning bool to returning ErrorCode with the [[nodiscard]] attribute aligns well with the PR objective of enhancing error handling. This ensures errors aren't accidentally ignored.


56-56: Good removal of eof_possible parameter

The removal of the eof_possible parameter from read_exact_length aligns with the PR objective of eliminating these flags in favor of returning EOF-related error codes directly.


62-62: Good template method alignment with error code approach

The read_numeric_value method now correctly returns an ErrorCode and includes the [[nodiscard]] attribute, consistent with the pattern applied to other methods in the class.


68-68: Good removal of eof_possible parameter from read_string

Similar to read_exact_length, removing the eof_possible parameter from read_string aligns with the PR objective of returning EOF-related error codes directly.


74-74: Trailing return type for seek_from_begin

The signature change for seek_from_begin to return ErrorCode is good, consistent with the other methods.


87-87: Good method signature update for get_pos

Changing get_pos to return an ErrorCode and take a reference parameter for the position aligns well with the error handling approach. This provides a clear way to handle errors when retrieving the current position.


91-92: Template method implementation now uses error code

The implementation of read_numeric_value now correctly uses and returns the ErrorCode from read_exact_length. This is a good change that aligns with the overall error handling approach.

@Bill-hbrhbr Bill-hbrhbr changed the title refactor(io_interface): Unify ReaderInterface error handling using ErrorCode and remove exception throwing; run clang-tidy on changed files. refactor(io_interface): Change ReaderInterface to return ErrorCodes instead of throwing exceptions; remove NOLINTs and fix clang-tidy issues. Apr 1, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title refactor(io_interface): Change ReaderInterface to return ErrorCodes instead of throwing exceptions; remove NOLINTs and fix clang-tidy issues. refactor(io_interface): Change ReaderInterface to return ErrorCodes instead of throwing exceptions; remove ReaderInterface NOLINTs and fix clang-tidy issues. Apr 1, 2025
@Bill-hbrhbr Bill-hbrhbr requested a review from davidlion April 1, 2025 04:08
@davidlion davidlion changed the title refactor(io_interface): Change ReaderInterface to return ErrorCodes instead of throwing exceptions; remove ReaderInterface NOLINTs and fix clang-tidy issues. > refactor(io_interface): Change ReaderInterface to return ErrorCodes instead of throwing exceptions; address clang-tidy violations in ReaderInterface. Apr 2, 2025
@davidlion davidlion changed the title > refactor(io_interface): Change ReaderInterface to return ErrorCodes instead of throwing exceptions; address clang-tidy violations in ReaderInterface. refactor(io_interface): Change ReaderInterface to return ErrorCodes instead of throwing exceptions; address clang-tidy violations in ReaderInterface. Apr 2, 2025
@Bill-hbrhbr Bill-hbrhbr merged commit c293831 into y-scope:main Apr 2, 2025
11 of 12 checks passed
@Bill-hbrhbr Bill-hbrhbr deleted the remove-try-reader-interface branch April 2, 2025 19:49
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.

2 participants