Skip to content

feat(error_handling): Port error_handling library and related unit tests from CLP core.#28

Merged
Bill-hbrhbr merged 7 commits intoy-scope:mainfrom
Bill-hbrhbr:add-error-handling-errorcode
Feb 26, 2025
Merged

feat(error_handling): Port error_handling library and related unit tests from CLP core.#28
Bill-hbrhbr merged 7 commits intoy-scope:mainfrom
Bill-hbrhbr:add-error-handling-errorcode

Conversation

@Bill-hbrhbr
Copy link
Copy Markdown
Collaborator

@Bill-hbrhbr Bill-hbrhbr commented Feb 25, 2025

Description

Port error_handling/ErrorCode lib and unit test from clp-core, so that the entire clp and other YScope cpp projects can easily apply this new ErrorCode system by linking against ystdlib::error_handling to referencing ystdlib::error_handling::ErrorCode.

The files are directly copied with the following minor changes:

  • All CLP namespaces/references are replaced with ystdlib
  • Split test-error_handling.cpp into multiple files and put them under ystdlib/src/error_handling/test, which helps us reuse the testing code when writing unit tests for TraceableException in the future.
    • Definition files:
      • test/constants.hpp
      • test/types.hpp
      • test/types.cpp
    • The actual test file:
      • test/test_ErrorCode.cpp

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

  • Unit tests pass as expected.

Summary by CodeRabbit

  • New Features

    • Introduced an enhanced error handling system that improves error reporting and diagnostic messaging for a more robust user experience.
  • Tests

    • Added comprehensive tests to ensure the reliability and consistency of the new error management capabilities.
  • Chores

    • Updated the build configuration and streamlined legacy testing components to support and maintain the improved error handling framework.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 25, 2025

Warning

Rate limit exceeded

@Bill-hbrhbr has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1eee1ee and 783ceed.

📒 Files selected for processing (1)
  • src/ystdlib/error_handling/test/test_ErrorCode.cpp (1 hunks)

Walkthrough

This pull request adjusts the project’s build configuration and introduces a new error handling module within the ystdlib directory. The existing test library (testlib) configuration and its associated files have been removed, and the build is now set up to compile and test the new error_handling module. The new module includes a header for error code handling, test infrastructure with constants, types, and comprehensive tests verifying error code behaviours and failure conditions. Additionally, the task file has been updated to reflect these changes.

Changes

File(s) Change Summary
src/ystdlib/CMakeLists.txt
taskfile.yaml
Updated build configuration by replacing the inclusion of the testlib subdirectory with error_handling and updating the G_TEST_TARGET_SUFFIXES variable accordingly.
src/ystdlib/error_handling/CMakeLists.txt Added a new CMake configuration defining the error_handling library along with its associated test source files.
src/ystdlib/error_handling/ErrorCode.hpp Introduced a new error handling framework that defines a concept (ErrorCodeEnumType), the ErrorCategory and ErrorCode classes, a function template (make_error_code), and a macro (YSTDLIB_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM) for integrating user-defined error enumerations with std::error_code.
src/ystdlib/error_handling/test/constants.hpp Added constants for error handling, including error category names, success/failure messages, and arrays of error conditions.
src/ystdlib/error_handling/test/types.cpp
src/ystdlib/error_handling/test/types.hpp
Implemented and defined error handling functionalities: enumerations for error codes, type aliases for error codes and categories, and methods that return category names, messages, and perform failure condition checks for specific error categories.
src/ystdlib/error_handling/test/test_ErrorCode.cpp Added unit tests to verify the error handling features, including the correct conversion of error codes, proper message retrieval, and validation of failure conditions.
src/ystdlib/testlib/CMakeLists.txt
src/ystdlib/testlib/hello.hpp
src/ystdlib/testlib/test-hello.cpp
Removed the obsolete test library configuration and associated files that previously supported test functionalities for testlib.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant ErrorCode
    participant ErrorCategory
    App->>ErrorCode: Construct error code using enum value
    ErrorCode->>ErrorCategory: Retrieve category details
    ErrorCategory-->>ErrorCode: Return category name and message handling
    ErrorCode->>App: Return std::error_code with message
Loading
sequenceDiagram
    participant Test
    participant ErrorValidator
    participant BinaryErrorCategory
    Test->>ErrorValidator: Provide BinaryErrorCode (e.g., Failure)
    ErrorValidator->>BinaryErrorCategory: Check error message and failure conditions
    BinaryErrorCategory-->>ErrorValidator: Return validation result
    ErrorValidator->>Test: Output test results (assertions)
Loading

Suggested reviewers

  • LinZhihao-723
  • davidlion
  • kirkrodrigues

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
Copy Markdown

@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/ystdlib/error_handling/test-Defs.cpp (1)

42-57: Good implementation of error category classes

The implementation of the equivalent() method is well-structured. A minor suggestion: the lambda function on line 52 could be simplified by removing the explicit return type specification since it's straightforward.

- [&](auto failure_condition) -> bool { return condition == failure_condition; }
+ [&](auto failure_condition) { return condition == failure_condition; }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e701d8 and 88a4c3e.

📒 Files selected for processing (10)
  • src/ystdlib/CMakeLists.txt (1 hunks)
  • src/ystdlib/error_handling/CMakeLists.txt (1 hunks)
  • src/ystdlib/error_handling/ErrorCode.hpp (1 hunks)
  • src/ystdlib/error_handling/test-Defs.cpp (1 hunks)
  • src/ystdlib/error_handling/test-Defs.hpp (1 hunks)
  • src/ystdlib/error_handling/test-ErrorCode.cpp (1 hunks)
  • src/ystdlib/testlib/CMakeLists.txt (0 hunks)
  • src/ystdlib/testlib/hello.hpp (0 hunks)
  • src/ystdlib/testlib/test-hello.cpp (0 hunks)
  • taskfile.yaml (1 hunks)
💤 Files with no reviewable changes (3)
  • src/ystdlib/testlib/CMakeLists.txt
  • src/ystdlib/testlib/test-hello.cpp
  • src/ystdlib/testlib/hello.hpp
✅ Files skipped from review due to trivial changes (2)
  • src/ystdlib/CMakeLists.txt
  • src/ystdlib/error_handling/CMakeLists.txt
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

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

  • src/ystdlib/error_handling/test-ErrorCode.cpp
  • src/ystdlib/error_handling/test-Defs.cpp
  • src/ystdlib/error_handling/test-Defs.hpp
  • src/ystdlib/error_handling/ErrorCode.hpp
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (4)
taskfile.yaml (1)

16-16: Change aligns with error_handling integration
Replacing the suffix "testlib" with "error_handling" is consistent with the new direction for error handling.

src/ystdlib/error_handling/test-ErrorCode.cpp (1)

1-64: Thorough test coverage
The test logic comprehensively exercises both success and failure paths, ensuring strong validation of error code behaviour.

src/ystdlib/error_handling/ErrorCode.hpp (1)

1-148: Comprehensive error handling framework
The code is structured to integrate cleanly with C++ standard error mechanisms, and there are no apparent correctness or performance issues.

src/ystdlib/error_handling/test-Defs.hpp (1)

1-33: Well-structured error code definitions

This header file is well organized with clear separation between constants, enum definitions, and type aliases. The use of enum classes with explicit underlying types (uint8_t) provides good type safety. The naming conventions are consistent throughout the file.

@Bill-hbrhbr Bill-hbrhbr changed the title feat: Port error_handling/ErrorCode lib and unit test from clp-core. feat: Port error_handling library with the redesigned ErrorCode system and unit tests from clp. Feb 25, 2025
Bill-hbrhbr and others added 2 commits February 26, 2025 16:57
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
Copy link
Copy Markdown
Member

@LinZhihao-723 LinZhihao-723 left a comment

Choose a reason for hiding this comment

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

For the PR title, how about:

feat(error_handling): Port `error_handling` library and related unit tests from CLP core.

Also, can u update the PR description before we merge (since we changed the unit test file names)?

@Bill-hbrhbr Bill-hbrhbr changed the title feat: Port error_handling library with the redesigned ErrorCode system and unit tests from clp. feat(error_handling): Port error_handling library and related unit tests from CLP core. Feb 26, 2025
@Bill-hbrhbr Bill-hbrhbr merged commit 2ed729f into y-scope:main Feb 26, 2025
8 checks passed
@Bill-hbrhbr Bill-hbrhbr deleted the add-error-handling-errorcode branch February 26, 2025 22:27
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