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

chore(dashmate): report port check errors #2245

Merged
merged 5 commits into from
Oct 19, 2024

Conversation

shumkov
Copy link
Member

@shumkov shumkov commented Oct 16, 2024

Issue being fixed or feature implemented

There are might be issues during port check that are stored as ERROR to dashmate doctor report. It makes it difficult to analyze. Timouts are not handled properly

What was done?

  • Store stringified error instead of error status to report
  • Fix port check timeout

How Has This Been Tested?

Running locally

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for port status checks, providing more informative feedback to users.
  • Bug Fixes

    • Improved reliability of port status retrieval by implementing robust error management.
  • Tests

    • Updated test suite for better handling of asynchronous behavior in port status checks.

@shumkov shumkov added the dashmate Dashmate related label Oct 16, 2024
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request focus on enhancing error handling in various components related to port status checks within the dashmate package. The collectSamplesTaskFactory function now wraps responses in a .catch() method, while the checkPortStatus method has been modified to reject promises with detailed error messages. Additionally, the getCoreScopeFactory and getTenderdashInfo functions have been updated to utilize a new PortStateEnum for error handling. Test modifications ensure that asynchronous behavior is correctly handled.

Changes

File Path Change Summary
packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js Enhanced error handling for port status responses using .catch().
packages/dashmate/src/status/providers.js Updated checkPortStatus to reject promises with detailed error messages; removed default ip.
packages/dashmate/src/status/scopes/core.js Added import for PortStateEnum; updated promise handling to assign PortStateEnum.ERROR on rejection.
packages/dashmate/src/status/scopes/platform.js Added import for PortStateEnum; modified getTenderdashInfo to incorporate error handling.
packages/dashmate/test/unit/status/scopes/core.spec.js Changed mockMNOWatchProvider to return asynchronous resolutions in tests.

Possibly related PRs

Suggested reviewers

  • QuantumExplorer
  • pshenmic

🐇 In the land of code where errors roam,
We wrapped them tight, gave them a home.
With enums in hand, we handle with care,
Port statuses safe, no need for despair!
So hop along, let’s code and play,
With better checks, we’ll save the day! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f85aa35 and 00511a4.

📒 Files selected for processing (1)
  • packages/dashmate/src/status/scopes/platform.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/dashmate/src/status/scopes/platform.js
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-09-26T14:28:54.892Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.

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.

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.

@shumkov shumkov self-assigned this Oct 16, 2024
@shumkov shumkov linked an issue Oct 16, 2024 that may be closed by this pull request
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)
packages/dashmate/src/status/scopes/platform.js (1)

97-97: LGTM: Consistent error handling in result processing

The updated destructuring of portStatusResult correctly handles both successful and failed port checks. This change ensures that the code continues execution even if a port check fails, which is consistent with the error handling improvements made earlier.

For improved clarity, consider using a more explicit null check:

const [httpPortState, p2pPortState] = portStatusResult.map((result) => (result.status === 'fulfilled' ? result.value : PortStateEnum.ERROR));

This makes it clear that failed checks result in PortStateEnum.ERROR rather than null.

packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js (1)

Line range hint 170-192: Overall improvement in error handling for port status checks

The changes consistently improve error handling across all port status checks (Core P2P, Gateway HTTP, and Tenderdash P2P). This enhancement aligns well with the PR objectives and previous learnings about error handling in the checkPortStatus function.

To further improve code readability and maintainability, consider extracting the common error handling logic into a separate function. This would reduce code duplication and make future updates easier. For example:

const checkPortStatusWithErrorHandling = async (port, externalIp) => {
  try {
    return await providers.mnowatch.checkPortStatus(port, externalIp);
  } catch (e) {
    return e.toString();
  }
};

Then, you could use this function in all three port check tasks:

const response = await checkPortStatusWithErrorHandling(port, config.get('externalIp'));

This refactoring would make the code more DRY (Don't Repeat Yourself) and easier to maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 908d0b3 and f5ed475.

📒 Files selected for processing (5)
  • packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js (3 hunks)
  • packages/dashmate/src/status/providers.js (4 hunks)
  • packages/dashmate/src/status/scopes/core.js (2 hunks)
  • packages/dashmate/src/status/scopes/platform.js (2 hunks)
  • packages/dashmate/test/unit/status/scopes/core.spec.js (3 hunks)
🧰 Additional context used
📓 Learnings (4)
📓 Common learnings
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-09-26T14:28:54.892Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
packages/dashmate/src/status/providers.js (2)
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-09-26T14:28:54.892Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
packages/dashmate/src/status/scopes/core.js (2)
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-09-26T14:28:54.892Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
packages/dashmate/src/status/scopes/platform.js (2)
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-09-26T14:28:54.892Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
🔇 Additional comments (14)
packages/dashmate/src/status/scopes/core.js (3)

2-2: LGTM: New import statement is correctly added.

The import of PortStateEnum is properly placed and will be used for error handling in the checkPortStatus call.


120-121: Great improvement in error handling for checkPortStatus.

This change aligns perfectly with the previous learnings about how mnowatch.checkPortStatus should handle failures. By catching potential errors and resolving with PortStateEnum.ERROR, we ensure that the Promise chain doesn't break and that errors are properly represented in the port state.


Line range hint 1-150: Overall, excellent improvements to error handling.

The changes in this file enhance the robustness of the getCoreScope function by properly handling potential errors in the checkPortStatus call. These modifications align well with previous learnings and best practices. The code remains clean and maintainable, with no apparent negative impacts on existing functionality.

packages/dashmate/src/status/scopes/platform.js (3)

2-2: LGTM: New import for PortStateEnum

The new import for PortStateEnum is correctly placed and necessary for the changes in the getTenderdashInfo function.


93-96: LGTM: Improved error handling for port status checks

The changes enhance the robustness of port status checks by:

  1. Using Promise.allSettled to attempt both checks regardless of individual failures.
  2. Catching errors and returning PortStateEnum.ERROR instead of rejecting the promise.

This implementation aligns with the previous feedback from shumkov in PR #2162, where it was suggested that failures should resolve with PortStateEnum.ERROR instead of rejecting the promise.


Line range hint 1-324: Summary: Improved error handling in port status checks

The changes in this file significantly enhance the robustness of port status checks in the getTenderdashInfo function. Key improvements include:

  1. Proper error handling using PortStateEnum.ERROR.
  2. Use of Promise.allSettled to ensure all checks are attempted.
  3. Consistent handling of failed checks in the result processing.

These changes align well with previous feedback and improve the overall reliability of the platform status reporting. The code is now better equipped to handle potential failures in port status checks without disrupting the entire process.

packages/dashmate/test/unit/status/scopes/core.spec.js (4)

81-81: LGTM: Improved asynchronous behavior simulation

The change from a synchronous return to mockMNOWatchProvider.resolves('OPEN'); is a good improvement. It better simulates the asynchronous nature of network operations, which is more realistic for port status checks. This change aligns well with the PR's objective of enhancing error handling in port checks.


222-222: LGTM: Consistent asynchronous behavior

This change is consistent with the previous modification, ensuring that all test cases are updated to work with the new asynchronous implementation of mockMNOWatchProvider. This consistency is crucial for maintaining the integrity of the test suite.


274-274: LGTM: Improved error handling simulation

The change to mockMNOWatchProvider.rejects(PortStateEnum.ERROR); is an excellent improvement. It properly simulates an asynchronous error scenario in port status checks, which is crucial for testing error handling. This change aligns well with the PR's objective and the best practices for handling port status check failures.


Line range hint 81-274: Verify corresponding implementation changes

The changes in this test file consistently improve the simulation of asynchronous behavior in mockMNOWatchProvider, which aligns well with the PR's objective of enhancing error handling in port checks. These modifications will lead to more realistic and robust tests.

To ensure full compatibility:

Please run the following script to verify that the corresponding implementation in the dashmate package has been updated to handle these asynchronous operations correctly:

This script will help ensure that the implementation matches the new test expectations for asynchronous port status checks.

✅ Verification successful

Asynchronous Handling Verified Successfully

The dashmate package correctly implements asynchronous handling for checkPortStatus using async/await, aligning with the test enhancements in core.spec.js. No further action is required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the dashmate package handles asynchronous port checks

# Test: Search for asynchronous handling of port checks in the dashmate package
rg --type javascript -g '!test' 'checkPortStatus.*\.(then|catch)' packages/dashmate/src

Length of output: 124


Script:

#!/bin/bash
# Description: Verify that the dashmate package handles asynchronous port checks

# Test: Search for asynchronous handling of port checks in the dashmate package
rg --type js -g '!test' 'checkPortStatus.*\.(then|catch)' packages/dashmate/src

Length of output: 81


Script:

#!/bin/bash
# Description: Search for all instances of `checkPortStatus` in the dashmate package

# Search for any usage of `checkPortStatus` regardless of async handling
rg 'checkPortStatus' packages/dashmate/src

# Additionally, search for async/await usage related to `checkPortStatus`
rg -A2 'async' packages/dashmate/src | rg 'checkPortStatus'

Length of output: 1846

packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js (3)

170-171: Improved error handling for Core P2P port status check

This change enhances the error handling for the Core P2P port status check. By adding a .catch() block and converting any errors to strings, we ensure that all errors are captured and stored in a consistent format. This aligns with the PR objective of improving error reporting in the dashmate doctor report.


181-182: Consistent error handling improvement for Gateway HTTP port status check

This change applies the same error handling improvement to the Gateway HTTP port status check as was done for the Core P2P port. It ensures consistent error reporting across different port checks, which enhances the overall reliability of the dashmate doctor report.


191-192: Consistent error handling across all port status checks

This change completes the implementation of improved error handling for all port status checks (Core P2P, Gateway HTTP, and Tenderdash P2P). The consistent approach ensures that all errors are captured and stored as strings, providing a uniform and more detailed error reporting mechanism in the dashmate doctor report.

packages/dashmate/src/status/providers.js (1)

Line range hint 88-135: Change in error handling may introduce unhandled promise rejections

The checkPortStatus function now rejects the promise with an Error object when an error occurs (lines 100, 112, 135), whereas previously it resolved with PortStateEnum.ERROR. According to previous learnings, failures should resolve with PortStateEnum.ERROR instead of rejecting the promise. This change could lead to unhandled promise rejections in code that expects a resolved value, potentially causing unexpected behavior.

Consider revising the error handling to resolve with PortStateEnum.ERROR as per previous conventions, or ensure that all calling code properly handles rejected promises.

Run the following script to verify how the checkPortStatus function is used throughout the codebase and ensure that promise rejections are handled appropriately:

#!/bin/bash
# Description: Find all usages of `checkPortStatus` and check if promise rejections are handled.

# Search for all JavaScript files containing `checkPortStatus` calls.
rg --type js -C 5 'checkPortStatus\('

This script will identify all instances where checkPortStatus is called. Please review these occurrences to confirm that promise rejections are properly handled to prevent potential issues.

@shumkov shumkov changed the title chore(dashmate): store port check errors to report chore(dashmate): report port check errors Oct 17, 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 (1)
packages/dashmate/src/status/providers.js (1)

Line range hint 86-142: Overall improvements in error handling, with some concerns.

The changes to the checkPortStatus function generally improve error reporting and handling, aligning with the PR objectives. However, there are a few points to consider:

  1. The removal of the default value for the ip parameter might affect backward compatibility.
  2. The change to reject promises instead of resolving with PortStateEnum.ERROR contradicts previous learnings. This inconsistency needs to be addressed or explained.
  3. The timeout handling is a good addition to prevent hanging requests.

Please review these points and ensure that the changes are consistent with the overall error handling strategy in the project.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b7547b1 and c4c9590.

📒 Files selected for processing (1)
  • packages/dashmate/src/status/providers.js (4 hunks)
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-09-26T14:28:54.892Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
packages/dashmate/src/status/providers.js (2)
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-09-26T14:28:54.892Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
🔇 Additional comments (3)
packages/dashmate/src/status/providers.js (3)

97-101: Improved error handling for non-200 status codes.

The new implementation rejects the promise with a detailed error message for non-200 status codes, which aligns with the PR objectives of providing more informative error reporting.


118-120: Enhanced response size limit handling.

The code now rejects the promise with a specific error message when the response size exceeds the limit, providing better clarity on the issue.


86-86: Consider backward compatibility implications of function signature change.

The ip parameter no longer has a default value. This change might break existing code that relies on the optional nature of this parameter.

To assess the impact, let's check for usages of this function:

✅ Verification successful

Function signature change does not affect existing usages.

All current calls to checkPortStatus provide both port and ip parameters, so removing the default value for ip does not break existing code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of checkPortStatus function
rg --type js 'checkPortStatus\s*\(' packages/

Length of output: 1065

pshenmic
pshenmic previously approved these changes Oct 18, 2024
@shumkov shumkov merged commit e7ad4f3 into v1.4-dev Oct 19, 2024
22 checks passed
@shumkov shumkov deleted the chore/dashmate/log-port-check-errors branch October 19, 2024 05:29
@shumkov shumkov added this to the 1.4.2 milestone Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashmate Dashmate related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log error status code for port check in dashmate doctor command
2 participants