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: prevent updater from panics #1492

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

Conversation

mmrrnn
Copy link
Collaborator

@mmrrnn mmrrnn commented Feb 7, 2025

fixes #1491

Description

Throw error instead of letting the app panic when something wrong happened while checking for updates

How Has This Been Tested?

Manually by turning off the wifi

Summary by CodeRabbit

  • Bug Fixes
    • Improved the update process reliability with enhanced error handling, ensuring smoother and more stable update checks for users.

@mmrrnn mmrrnn marked this pull request as ready for review February 7, 2025 09:03
Copy link

coderabbitai bot commented Feb 11, 2025

Walkthrough

This change improves the error handling in the check_for_update method of the updates manager. The method now uses separate match statements to catch and log errors at each stage—setting the endpoints, building the updater, and checking for updates. If any step fails, a warning is logged and the function returns Ok(None), preventing panics from unwrapped errors. Public APIs remain unchanged.

Changes

File Path Change Summary
src-tauri/.../updates_manager.rs Enhanced error handling in check_for_update by introducing match statements for endpoint setup, updater building, and update checking.

Sequence Diagram(s)

sequenceDiagram
    participant UM as UpdatesManager
    participant UB as UpdaterBuilder
    participant Logger as Logging

    UM->>UB: Call updater_builder()
    alt Setting endpoints successful
        UB-->>UM: Endpoints set
        UM->>UB: Build updater
        alt Building updater successful
            UB-->>UM: Updater built
            UM->>UB: Check for updates
            alt Update check successful
                UB-->>UM: Update info returned
            else Update check failure
                Logger->>UM: Log warning
                UM-->>UM: Return Ok(None)
            end
        else Building updater failure
            Logger->>UM: Log warning
            UM-->>UM: Return Ok(None)
        end
    else Setting endpoints failure
        Logger->>UM: Log warning
        UM-->>UM: Return Ok(None)
    end
Loading

Assessment against linked issues

Objective (from #1491) Addressed Explanation
Handle missing downloads gracefully without panicking, especially for Linux releases.

Poem

I'm a rabbit with a smile, hopping down the lane,
No more panics in updates, errors handled plain.
Each match and log now sings a tune so clear,
Keeping release checks gentle, calm, and dear.
Hoppin' through the code with cheer, no panic here!
🐰✨


🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Copy link

@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

🧹 Nitpick comments (4)
src-tauri/src/updates_manager.rs (4)

145-154: Consider using a Semantic Versioning comparator rather than plain string comparison.

Currently, the closure uses update.version > current (or != when enable_downgrade) to decide if an update is newer. If these versions contain semantic prefixes or follow complex versioning formats, a direct string comparison may yield incorrect conclusions (e.g., "2.10" is lexically less than "2.2"). Consider parsing the versions via a known semver library for more robust comparison.


155-161: Re-examine returning Ok(None) upon endpoints error.

When the .endpoints() call fails, you log the error and return Ok(None). This effectively treats "failing to set endpoints" the same as "no updates available." If differentiating these scenarios is useful, consider returning a more descriptive error or a custom type to distinguish between "no updates found" vs. "error setting endpoints."


162-168: Maintain consistency in error reporting or surface the cause.

Similar to the previous match, an error in builder.build() results in a warning and an Ok(None). If you need upstream handling or logging to reflect the specific reason, consider returning a dedicated error variant or an error message instead of silently mapping it to None.


169-175: Ensure callers can differentiate between "no update" and "update check error."

Currently, errors from .check() are also logged as warnings, and the function returns Ok(None). This prevents a panic but conflates genuine 'no update' scenarios with 'failed to check' scenarios. For clarity, you might wrap the None in a result or provide an explicit error subtype to inform the calling function that an error occurred.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ff59462 and e5d5da5.

📒 Files selected for processing (1)
  • src-tauri/src/updates_manager.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: cargo checks (fmt, clippy, check)
  • GitHub Check: machete
  • GitHub Check: tauri-build

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.

PANIC: Failed to check for updates: ReleaseNotFound
1 participant