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(cli): set timeout for latest version check and avoid failing the CLI #1559

Merged
merged 1 commit into from
Jul 6, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Jul 6, 2024

Fixes #1529

Copy link
Contributor

coderabbitai bot commented Jul 6, 2024

Walkthrough

Walkthrough

The recent changes focus on improving the robustness and efficiency of the CLI operations, particularly for the generate and info functions. The generate function now ensures sequential execution for plugin runs and version checks to prevent timeouts. The info function has been updated with better error handling and restructured logic for retrieving the latest version. Additionally, the utility functions in cli-util.ts have been refined to support these improvements.

Changes

Files Change Summary
generate.ts Ensured sequential execution of plugin runs and version checks to prevent timeouts in CPU-bound operations.
info.ts Reordered imports, modified latest version retrieval, and improved error handling within the info function.
cli-util.ts Removed getLatestVersion import, added CHECK_VERSION_TIMEOUT constant, refactored checkNewVersion, and added getLatestVersion function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant NPM
    
    User->>CLI: run generate()
    CLI->>CLI: execute plugins sequentially
    CLI->>CLI: check plugin versions
    Note right of CLI: Sequential execution to avoid CPU timeouts
    
    User->>CLI: run info()
    CLI-->>NPM: getLatestVersion()
    NPM-->>CLI: return version info or error
    CLI->>User: display version info or error message
    Note right of CLI: Improved error handling and better version retrieval logic
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure the CLI does not fail when running generate without internet (1529)
Improve error messages in info function (general improvement)

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b46743b and 92e7de8.

Files ignored due to path filters (2)
  • packages/schema/package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
Files selected for processing (3)
  • packages/schema/src/cli/actions/generate.ts (1 hunks)
  • packages/schema/src/cli/actions/info.ts (2 hunks)
  • packages/schema/src/cli/cli-util.ts (3 hunks)
Additional comments not posted (6)
packages/schema/src/cli/actions/info.ts (2)

4-4: LGTM! Imports are correct.

The import statements are correct and relevant for the functionality implemented.


28-36: LGTM! Enhanced error handling.

The changes improve error handling and provide better user feedback when fetching the latest version.

packages/schema/src/cli/actions/generate.ts (1)

46-51: LGTM! Sequential execution of plugins and version checks.

The changes ensure sequential execution of plugin runs and version checks to prevent CPU-bound plugin operations from causing version check timeouts.

packages/schema/src/cli/cli-util.ts (3)

22-22: LGTM! Reasonable timeout value.

The CHECK_VERSION_TIMEOUT constant is set to 1000 milliseconds, which seems reasonable for network operations.


271-277: LGTM! Improved error handling in version check.

The changes improve error handling and ensure that the function does not fail if the version check fails.


284-300: LGTM! Robust version fetching with timeout.

The getLatestVersion function fetches the latest version of Zenstack from the npm registry with a timeout and handles errors gracefully, providing better user feedback.

@ymc9 ymc9 merged commit df32680 into dev Jul 6, 2024
13 checks passed
@ymc9 ymc9 deleted the fix/issue-1529 branch July 6, 2024 19:22
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.

1 participant