Skip to content

Conversation

QYuQianchen
Copy link
Contributor

Close #6560
The root cause it that self-registration on the network registry is not enabled. The "div 0" error is expected.
The error can be better handled on the smart contract level, which will be tackled in #5501

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request modify the eligiblez function in the hoprd/rest-api/src/checks.rs file to enhance error handling. A match statement is introduced to specifically check for HoprLibError::ChainApi errors that indicate a "division by zero." In such cases, the function will return a 412 Precondition Failed status with a relevant message. For other errors, it continues to return a 500 Internal Server Error status, maintaining the previous error handling behavior.

Changes

File Change Summary
hoprd/rest-api/src/checks.rs Enhanced error handling in eligiblez function to return 412 Precondition Failed for specific division by zero errors.

Assessment against linked issues

Objective Addressed Explanation
Improve error handling for /eligiblez endpoint (6560)
Return specific status for division by zero errors (6560)

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 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.

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.

@QYuQianchen QYuQianchen added effort:small time needed to complete review complexity:normal how hard is the review crate:hoprd-api bugfix labels Nov 7, 2024
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 and nitpick comments (2)
hoprd/rest-api/src/checks.rs (2)

75-75: Fix typo and enhance comment clarity.

The comment contains a typo and could be more descriptive about the business logic.

-                // when the error is deivision by zero, it's caused by the self-registration is forbidden to the public, and thus returns false.
+                // A "division by zero" error indicates that self-registration is not enabled in the NetworkRegistry contract, making the node ineligible.

77-81: Improve error message clarity and reduce duplication.

The error message could be more specific about the self-registration restriction, and the duplicate message should be extracted to a constant.

+    const INELIGIBLE_MESSAGE: &str = "Node not eligible: self-registration is not enabled";
+
     match hopr.get_eligibility_status().await {
         Ok(true) => (StatusCode::OK, "").into_response(),
-        Ok(false) => (StatusCode::PRECONDITION_FAILED, "Node not eligible").into_response(),
+        Ok(false) => (StatusCode::PRECONDITION_FAILED, INELIGIBLE_MESSAGE).into_response(),
         Err(e) => {
             match e {
                 hopr_lib::errors::HoprLibError::ChainApi(chain_api_err) => {
                     if chain_api_err.to_string().contains("division by zero") {
-                        (StatusCode::PRECONDITION_FAILED, "Node not eligible").into_response()
+                        (StatusCode::PRECONDITION_FAILED, INELIGIBLE_MESSAGE).into_response()
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1d90958 and 2e756e3.

📒 Files selected for processing (1)
  • hoprd/rest-api/src/checks.rs (1 hunks)
🔇 Additional comments (2)
hoprd/rest-api/src/checks.rs (2)

73-85: LGTM! Error handling approach is well-structured.

The new error handling correctly differentiates between chain API errors and other errors, providing appropriate status codes and maintaining backward compatibility.


76-82: Verify error handling in the NetworkRegistry contract.

The code assumes that a "division by zero" error specifically indicates disabled self-registration. Let's verify this assumption in the contract code.

Copy link
Contributor

@Teebor-Choka Teebor-Choka left a comment

Choose a reason for hiding this comment

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

What is the result now? Will the eligiblez endpoint actually return false if not eligible and true if eligible?

@Teebor-Choka Teebor-Choka added the bug Something isn't working label Nov 7, 2024
@QYuQianchen
Copy link
Contributor Author

Yes, and also throw error when it's actually an error

QYuQianchen and others added 3 commits November 7, 2024 17:24
Co-authored-by: Tibor <9529609+Teebor-Choka@users.noreply.github.com>
Co-authored-by: Lukas <lukas.pohanka@inina.net>
@Teebor-Choka Teebor-Choka force-pushed the q/fix-eligiblez-endpoint branch from 00236cb to 38ce66e Compare November 7, 2024 16:24
@NumberFour8 NumberFour8 enabled auto-merge November 7, 2024 18:50
@NumberFour8 NumberFour8 added this to the 2.2.0-rc.1 milestone Nov 7, 2024
@NumberFour8 NumberFour8 added this pull request to the merge queue Nov 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2024
@NumberFour8 NumberFour8 merged commit 30e284f into master Nov 7, 2024
27 of 28 checks passed
@NumberFour8 NumberFour8 deleted the q/fix-eligiblez-endpoint branch November 7, 2024 20:40
@coderabbitai coderabbitai bot mentioned this pull request Nov 12, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bugfix complexity:normal how hard is the review crate:hoprd-api effort:small time needed to complete review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Endpoint /eligiblez is not working
4 participants