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

fix(dashmate): status command fails if drive is not running #2364

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

shumkov
Copy link
Member

@shumkov shumkov commented Dec 2, 2024

Issue being fixed or feature implemented

The dashmate status is failing if drive is restarting

ServiceIsNotRunningError: Service drive_abci for mainnet is not running. Please run the service first.

What was done?

  • Handled service is not running error

How Has This Been Tested?

Running command 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

  • New Features

    • Introduced a new error handling mechanism for when services are not running, enhancing the robustness of the application.
  • Bug Fixes

    • Improved error management in the getDriveInfo function to prevent unnecessary error throws when the service is down.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes introduce a new error class, ServiceIsNotRunningError, to enhance error handling in the getDriveInfo function within the platform.js file. The function's catch block now checks for this new error type alongside existing error checks, allowing for more graceful handling when the service is not running. An import statement for the new error class has also been added, while the overall structure of related functions remains unchanged.

Changes

File Path Change Summary
packages/dashmate/src/status/scopes/platform.js Introduced ServiceIsNotRunningError class; modified getDriveInfo to handle this error type.

Possibly related PRs

Suggested reviewers

  • QuantumExplorer
  • pshenmic

🐰 In the code, a new error hops,
To catch the service when it stops.
With graceful checks, it now can see,
If the drive's not running, let it be!
A smoother path for all to roam,
In the land of code, we find our home! 🌼


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 added this to the v1.6.x milestone Dec 2, 2024
@shumkov shumkov self-assigned this Dec 2, 2024
@shumkov
Copy link
Member Author

shumkov commented Dec 3, 2024

@CodeRabbit review

Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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/scopes/platform.js (1)

222-223: Consider adding debug logging and documentation

While the error handling is correct, consider these improvements for better maintainability:

  1. Add debug logging for ServiceIsNotRunningError case
  2. Add a comment explaining why we suppress this error
     } catch (e) {
       // Throw an error if it's not a Drive issue
       if (!(e instanceof DockerComposeError
         && e.dockerComposeExecutionResult
         && e.dockerComposeExecutionResult.exitCode !== 0)
           && !(e instanceof ServiceIsNotRunningError)) {
+        // Log the error if in debug mode
+        if (process.env.DEBUG) {
+          console.error('Error getting Drive version:', e);
+        }
         throw e;
       }
+      // We suppress DockerComposeError with non-zero exit code and ServiceIsNotRunningError
+      // as these are expected when the service is starting up or not running
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 895c73c and 01ace99.

📒 Files selected for processing (1)
  • packages/dashmate/src/status/scopes/platform.js (2 hunks)
🔇 Additional comments (3)
packages/dashmate/src/status/scopes/platform.js (3)

9-9: LGTM: Import statement is well-placed

The import follows the established pattern and is appropriately grouped with other error-related imports.


222-223: LGTM: Error handling enhancement matches PR objective

The addition of ServiceIsNotRunningError handling prevents the status command from failing when the drive service is not running, which directly addresses the PR's goal.


9-9: Verify error handling consistency

Let's verify the usage of ServiceIsNotRunningError and similar error handling patterns across related files.

Also applies to: 222-223

✅ Verification successful

Let me analyze the error handling patterns further by checking the implementation and usage of ServiceIsNotRunningError.


Let me check the actual implementation of ServiceIsNotRunningError and its relationship with DockerComposeError.


Based on the comprehensive analysis of the error handling implementation and usage patterns, I can now provide the final response:

Error handling is consistent and properly implemented

The error handling in platform.js follows a consistent pattern where:

  • ServiceIsNotRunningError is correctly imported and used for service availability checks
  • It's properly handled alongside DockerComposeError in the catch blocks
  • Both errors extend AbstractError and provide appropriate context
  • The error handling hierarchy and flow aligns with the Docker service management requirements
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent error handling patterns

# Find all files that import ServiceIsNotRunningError
echo "Files importing ServiceIsNotRunningError:"
rg "import.*ServiceIsNotRunningError" --type js

# Find similar error handling patterns
echo -e "\nSimilar error handling patterns:"
rg "instanceof (DockerComposeError|ServiceIsNotRunningError)" --type js -A 3

Length of output: 1661


Script:

#!/bin/bash
# Check ServiceIsNotRunningError implementation and its usage in catch blocks

# Find ServiceIsNotRunningError implementation
echo "ServiceIsNotRunningError implementation:"
ast-grep --pattern 'class ServiceIsNotRunningError {
  $$$
}'

# Find catch blocks handling these errors
echo -e "\nError handling in catch blocks:"
rg "catch.*\{" -A 5 --type js packages/dashmate/src/commands/core/cli.js packages/dashmate/src/docker/DockerCompose.js

# Check if there are other similar error classes
echo -e "\nSimilar error classes:"
fd -e js -x grep -l "class.*Error extends" {}

Length of output: 10441


Script:

#!/bin/bash
# Check error class implementations and their relationships

# Find ServiceIsNotRunningError implementation
echo "ServiceIsNotRunningError implementation:"
cat packages/dashmate/src/docker/errors/ServiceIsNotRunningError.js

# Find DockerComposeError implementation
echo -e "\nDockerComposeError implementation:"
cat packages/dashmate/src/docker/errors/DockerComposeError.js

# Check usage in platform.js
echo -e "\nError handling in platform.js:"
cat packages/dashmate/src/status/scopes/platform.js

Length of output: 12743

@shumkov shumkov merged commit 2f8c3f6 into master Dec 3, 2024
23 checks passed
@shumkov shumkov deleted the fix/dashmate/fix-status-drive-is-not-responding branch December 3, 2024 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants