Skip to content

refactor: Add error code in worker. #116

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

sitaowang1998
Copy link
Collaborator

@sitaowang1998 sitaowang1998 commented Apr 25, 2025

Description

Refactor worker to use error code and Result.

Resolves #106. Resolves #110.

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

  • GitHub workflows pass.
  • Unit tests pass in dev container.
  • Integration tests pass in dev container.

Summary by CodeRabbit

  • New Features
    • Introduced detailed error codes for worker operations, providing clearer feedback on specific error conditions.
  • Refactor
    • Improved error handling by replacing optional and boolean returns with a structured result type that includes explicit error codes.
  • Bug Fixes
    • Enhanced reliability by ensuring all failure cases return meaningful error messages instead of generic failures.

@sitaowang1998 sitaowang1998 requested a review from a team as a code owner April 25, 2025 00:02
Copy link
Contributor

coderabbitai bot commented Apr 25, 2025

## Walkthrough

This change introduces a new error code system for the worker component by defining a `WorkerErrorCodeEnum` and integrating it with the `ystdlib::error_handling` framework. The error handling in `worker.cpp` is refactored to use `ystdlib::error_handling::Result` types with explicit error codes instead of `std::optional` or boolean returns. The build configuration is updated to include the new error code files. This refactor enables more granular and consistent error reporting within the worker logic.

## Changes

| File(s)                                                    | Change Summary                                                                                                    |
|------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| src/spider/CMakeLists.txt                                  | Updated build configuration to include `worker/WorkerErrorCode.cpp` and `worker/WorkerErrorCode.hpp` in sources. |
| src/spider/worker/WorkerErrorCode.cpp<br>src/spider/worker/WorkerErrorCode.hpp | Introduced new error code enum, error code type alias, and error category with message mapping for worker errors. |
| src/spider/worker/worker.cpp                               | Refactored error handling in core functions to use typed error codes and `Result` types instead of optionals/booleans. |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant TaskLoop
    participant Worker
    participant Storage
    participant Executor

    TaskLoop->>Worker: setup_task()
    Worker->>Storage: connect, fetch task details
    Storage-->>Worker: success or WorkerErrorCode
    Worker-->>TaskLoop: Result<task buffers, WorkerErrorCode>

    TaskLoop->>Worker: parse_outputs()
    Worker-->>TaskLoop: Result<outputs, WorkerErrorCode>

    TaskLoop->>Worker: handle_executor_result()
    Worker->>Executor: run task
    Executor-->>Worker: result
    Worker->>Storage: submit result
    Storage-->>Worker: success or WorkerErrorCode
    Worker-->>TaskLoop: Result<void, WorkerErrorCode>

Assessment against linked issues

Objective Addressed Explanation
Refactor handle_executor_result to use ErrorCode and propagate detailed errors (#106)
Replace error code constants with ErrorCode from ystdlib-cpp and update logic (#110)
Ensure consistent error codes across worker component (#110)

Possibly related PRs

Suggested reviewers

  • davidlion

<!-- walkthrough_end -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACJ/ADM0MXwKLgBBWnpKCmSFJRQsAHdkgGtKaMgCtGQHAWZ1Gno5MNgPbERKe3U0fEqMIgBGAE5BgA50ZFtIDEcBDv7+gDZ85o9ZMEQmbhIAekRueCU+f258RHVk2Q0YFshmbSwGWExSfIl8LylkeMSCCng+lYVEodJjME7kDChAj5JgUE5UGiAtoefBxSBZHJMJTITD0XA3AAGNmk3lwBLCsi2VzgqGw3Fo1A8aAy/kQ7RxGHorPenxQbOCyDM/QADEtcZAhSLqTdJsyWqywvhAbx8CIxAByZBMSF/AR4eD4LBEbAHEhef7SdCcvlTfChNCQAT+NDFf5ERhPPokK4AEXwDEc7GoBqwdIZNGQBUoHhI6nlt2ZKL4ShIbHo2Aw5AY0kQzkukAAamhzeGQ/YaNxkP8G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Iq/LEllleSuZcDAMuKtVuxeKUl91WgAzhLUrxKQSUSaTTS8BEAZKoqAqr8jKIrMrllerkh+rSrEhyq5LKrKBPK8N4ryQ6rkrpkGqMrZKUKUkvAuqzqsYLr1KYrArW1ZCarnq0roR3rDLmrfDVFuc2qiBAj2Tfqer/rVLAb/BYqQbITRrfLDhwtq5JqUsRyZrG85rfSsBFr+KZ4wxjYRK0qqSecaS6T4YKBGT2SZKeiLLFLrL0aDqgb3LSA9LfgDLjqfLzKFKrKVLbK/KAqnKAJww3LocSAHrwrxb+bMbga61gqAJQqxaxr8borNajqvL1bxr64sa60JogF6Tkgnr1rJkUqobHRRTwbxLIaGamr5kfDOc4b/DEaOrkauSDbSNZ8+4ibu8SaCRTNNNBZSZ+EMyqYEYWDU5UYmY0AWY2D2ZcYuYqACZeZiYBYDB46GJ1AxoDhszPwCEfwxpPl7p+Y46oYJ4BBhRhQBARgRgFhswRg4gAAmVuhgEYfoEYAAdl7pFGFEGESDbuzBHtGFoBGFoAABZBh6ASYm6BAABmYUOgKe/oBgBYBkOIYUIYYUAAVjPsnv6BHriFoAWF7sGE3t7s3pIH6AEDiDPt7pIBfobuLqbpFFoDPriBGCXrPs3v2JHs3rPpIEGBIGFE3tXpIBHrPrQAftbuFFAcSDPvvuwbGHXogEgB7t7qXrQAWDbvboWBGF7vfq7rPpGGgZHpGAYBHoEAWE3qXtmGXuFEXu4aXo8Ahj/oIdLtwHLtoErpIH+Ssphn0CAA= -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=y-scope/spider&utm_content=116):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `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 explain this code block.`
  -	`@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 explain its main purpose.`
  - `@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.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

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](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

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

🔭 Outside diff range comments (2)
src/spider/worker/worker.cpp (2)

243-270: ⚠️ Potential issue

Possible out-of-bounds access when result_buffers.size() < task.get_num_outputs()

The loop indexes result_buffers[i] up to task.get_num_outputs().
If the executor unexpectedly returns fewer buffers, this will dereference past the end and trigger UB before the size mismatch can be reported.

Guard early:

if (result_buffers.size() != task.get_num_outputs()) {
    spdlog::error("Result buffer count mismatch (expected {}, got {})",
                  task.get_num_outputs(), result_buffers.size());
    return WorkerErrorCodeEnum::TaskOutputInvalid;
}

This prevents a crash and yields a meaningful error.


326-340: 🛠️ Refactor suggestion

Propagate detailed parsing error instead of generic failure

handle_executor_result converts any parsing error to TaskOutputInvalid, even when parse_outputs has already produced a richer code (e.g., TaskOutputUnavailable).
Return the exact output_result.error() unmodified to preserve diagnostics:

-        return spider::worker::WorkerErrorCodeEnum::TaskOutputInvalid;
+        return output_result.error();
🧹 Nitpick comments (6)
src/spider/CMakeLists.txt (1)

64-66: Avoid mixing interface headers into the SOURCES list

WorkerErrorCode.hpp is a public‐interface header yet it is added to SPIDER_WORKER_SOURCES.
While CMake will tolerate headers in a source list, generators (Xcode/VS) will treat it as a “compilable” file, cluttering the project tree and occasionally triggering IDE-specific warnings.

 set(SPIDER_WORKER_SOURCES
 …
-    worker/WorkerErrorCode.cpp
-    worker/WorkerErrorCode.hpp   # ← move this
+    worker/WorkerErrorCode.cpp
 …
 )

# Then add to a header list exposed with PUBLIC visibility, e.g.
target_sources(spider_worker PUBLIC worker/WorkerErrorCode.hpp)

Keeping implementation and interface lists separate improves IDE ergonomics and avoids accidental compilation of headers.

src/spider/worker/WorkerErrorCode.hpp (1)

8-18: Consider introducing an Unknown/Unspecified sentinel and revisiting the Storage placeholder

  1. A generic Unknown (or Unspecified) value is helpful when converting foreign or unexpected errors into the worker domain without losing information.
  2. The in-code comment states “Storage related errors will be removed …” yet the enum still exposes StorageError. If removal is planned, mark it [[deprecated]] or drop it now to avoid API churn.
 enum class WorkerErrorCodeEnum : uint8_t {
     Success = 0,
     CmdLineArgumentInvalid = 1,
     TaskArgumentInvalid = 2,
     TaskFailed = 3,
     TaskOutputUnavailable = 4,
     TaskOutputInvalid = 5,
-    // Storage related errors will be removed and use storage error codes instead
-    StorageError = 6,
+    StorageError [[deprecated("Use storage::StorageErrorCode instead")]] = 6,
+    Unknown = 255
 };

This keeps the contract future-proof while signalling imminent deprecation.

src/spider/worker/WorkerErrorCode.cpp (2)

12-18: Define the category object inside the namespace to avoid ODR traps

cWorkerErrorCategoryName is currently a global constexpr string. Moving it inside spider::worker avoids potential clashes if another TU defines the same symbol.

-constexpr std::string_view cWorkerErrorCategoryName = "Worker Error Code";
+namespace spider::worker {
+constexpr std::string_view cWorkerErrorCategoryName = "Worker Error Code";
+} // namespace spider::worker

Remember to qualify references accordingly.


20-41: Exhaustive switch: return Unknown instead of a string literal

The default branch returns a raw string "Unknown error".
Returning a concrete enum (WorkerErrorCodeEnum::Unknown) or asserting unreachable would be more type-safe. At the very least, factor the literal into a static constant to avoid duplication.

-        default:
-            return "Unknown error";
+        default:
+            return "Unknown error";

(If you adopt the Unknown sentinel proposed earlier, this branch can become unreachable.)

src/spider/worker/worker.cpp (2)

205-215: Prefer returning ErrorCode explicitly to avoid overloaded conversions

return WorkerErrorCodeEnum::StorageError;

relies on an implicit conversion from the enum to WorkerErrorCode.
While the alias currently provides such a constructor, being explicit improves readability and guards against future API changes:

-        return spider::worker::WorkerErrorCodeEnum::StorageError;
+        return spider::worker::WorkerErrorCode{spider::worker::WorkerErrorCodeEnum::StorageError};

224-232: Unnecessary std::move on a local when returning

return std::move(optional_arg_buffers.value());

Moving a local that is about to be returned inhibits NRVO and produces the same code as a copy elision in modern compilers, sometimes even worse. Simply return the value:

-    return std::move(optional_arg_buffers.value());
+    return optional_arg_buffers.value();

[performance]

🧰 Tools
🪛 Cppcheck (2.10-2)

[performance] 231-231: Using std

(returnStdMoveLocal)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4830d26 and fb00b88.

📒 Files selected for processing (4)
  • src/spider/CMakeLists.txt (1 hunks)
  • src/spider/worker/WorkerErrorCode.cpp (1 hunks)
  • src/spider/worker/WorkerErrorCode.hpp (1 hunks)
  • src/spider/worker/worker.cpp (12 hunks)
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/spider/worker/worker.cpp

[performance] 231-231: Using std

(returnStdMoveLocal)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: lint
🔇 Additional comments (3)
src/spider/worker/WorkerErrorCode.hpp (1)

20-23: Expose WorkerErrorCode directly in the namespace documentation

using WorkerErrorCode = … is great, but add a brief comment explaining that the alias enables implicit construction from WorkerErrorCodeEnum – this will help new contributors understand why plain enum values can be returned from Result<T, WorkerErrorCode>.

src/spider/worker/worker.cpp (2)

35-40: Good workaround for the Valgrind header clash

Temporarily undefining QUICKCPPLIB_ENABLE_VALGRIND before including Result.hpp sidesteps the
Abseil/QuickCPPLib conflict (issue #59) without polluting the public interface. Nice!


420-426: Minor logic tweak: prefer result.is_success() over has_value() for Result<void, …>

Result<void, E>::has_value() works, but semantically is_success() (if available in ystdlib) conveys intent more clearly—there is no contained value to “have”.

Does ystdlib::error_handling::Result expose an is_success() helper? If so, consider switching.

@davidlion davidlion added the on hold On hold temporarily label May 5, 2025
@davidlion
Copy link
Member

On hold until quickcpplib/outcome dependency is resolved to avoid needing #undef QUICKCPPLIB_ENABLE_VALGRIND.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 10d5f84 and 8f24a60.

📒 Files selected for processing (2)
  • src/spider/CMakeLists.txt (1 hunks)
  • src/spider/worker/worker.cpp (12 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/spider/CMakeLists.txt
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
🔇 Additional comments (11)
src/spider/worker/worker.cpp (11)

57-57: LGTM! Proper include for the new error handling system.

The inclusion of WorkerErrorCode.hpp is correctly added to support the new error handling refactoring.


198-199: Excellent documentation and type signature improvement.

The function documentation clearly explains the new return behaviour, and the Result type provides much better error semantics than the previous std::optional.

Also applies to: 205-206


214-214: Well-structured error code mapping.

The refactoring correctly maps different failure scenarios to appropriate error codes:

  • Storage connection failures → StorageError
  • Task fetch failures → StorageError
  • Invalid task arguments → TaskArgumentInvalid

This provides much clearer error semantics than returning std::nullopt.

Also applies to: 222-222, 229-229


231-231: Proper success case handling.

The function correctly returns the successful result by moving the value, maintaining efficiency while adhering to the new Result pattern.


234-245: Enhanced function documentation and signature.

The documentation clearly explains the new return behaviour, and the Result type provides better error handling than the previous implementation.


263-263: Appropriate error code for parsing failure.

The function correctly returns TaskOutputInvalid when output parsing fails, which is more descriptive than the previous approach.


282-284: Improved function documentation and return type.

The documentation is clear about the new return behaviour, and Result<void, WorkerErrorCode> is the appropriate type for operations that either succeed or fail with an error code.

Also applies to: 291-291


299-299: Comprehensive error code coverage.

The function correctly maps different failure scenarios to specific error codes:

  • Storage connection failures → StorageError
  • Task execution failures → TaskFailed
  • Result buffer parsing failures → TaskOutputUnavailable
  • Storage submission failures → StorageError

This provides much clearer error semantics than the previous boolean return.

Also applies to: 310-310, 323-323, 358-358


326-330: Proper Result type integration.

The code correctly:

  • Uses Result type for the output parsing operation
  • Checks has_value() to determine success/failure
  • Propagates errors using output_result.error()
  • Extracts successful values using output_result.value()

This demonstrates proper integration with the new error handling system.

Also applies to: 339-339, 342-342


360-360: Correct success indication.

Using ystdlib::error_handling::success() is the proper way to indicate successful completion for a Result<void, ErrorCode> type.


387-396: Consistent Result handling in the main loop.

The task_loop function correctly handles the new Result types:

  • Properly declares and uses Result types for setup operations
  • Uses has_value() to check success/failure
  • Extracts values using value() method
  • Handles both setup and execution result checking consistently

The error handling flow maintains the existing retry logic while providing better error reporting.

Also applies to: 420-426

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

Successfully merging this pull request may close these issues.

refactor: Use ErrorCode from ystdlib-cpp in the worker component refactor: Use ErrorCode from ystdlib-cpp in handle_executor_result
2 participants