shuru-project / shuru

A Task Runner and Version Manager for Node.js & Python, Built in Rust!
MIT License
7 stars 4 forks source link

Refine `VersionManagerError` for More Detailed Error Handling #4

Open harshdoesdev opened 5 days ago

harshdoesdev commented 5 days ago

Good First Issue: Refine VersionManagerError for More Detailed Error Handling

Background

In the current Error enum, the VersionManagerError variant is used as a catch-all for errors related to the version management process, but it only passes a generic string message. This makes it difficult to distinguish between different types of version management issues (e.g., download failures, extraction errors, build issues, etc.).

To improve error handling and provide more detailed error information, we should create more specific error types under the VersionManagerError variant. This will help pinpoint the exact nature of the failure and improve the clarity of the error messages.

Task

  1. Create Specific Error Types:

    • Introduce more granular error types within the VersionManagerError to handle specific scenarios such as:
      • Download failure
      • Extraction failure
      • Build failure
      • Installation failure
  2. Update Error Enum:

    • Replace the current string-based VersionManagerError with a detailed enum that categorizes different error types. The enum should include fields for context (e.g., file paths, URLs) when relevant.
  3. Refactor Code:

    • Refactor the parts of the code that currently pass string messages for VersionManagerError to use the newly created specific error types.

Example

Current Error Enum:

#[derive(Debug, Error)]
pub enum Error {
    // Other variants...
    #[error("Version manager error: '{0}'")]
    VersionManagerError(String),
    // ...
}

Updated Error Enum:

#[derive(Debug, Error)]
pub enum Error {
    // Other variants...
    #[error("Version manager error")]
    VersionManagerError(#[from] VersionManagerError),
    // ...
}

#[derive(Debug, Error)]
pub enum VersionManagerError {
    #[error("Failed to download version from {url}: {source}")]
    DownloadError {
        url: String,
        source: reqwest::Error,
    },
    #[error("Failed to extract archive: {path}")]
    ExtractionError {
        path: String,
        source: std::io::Error,
    },
    #[error("Build process failed.")]
    BuildError,
    #[error("Installation failed.")]
    InstallationError,
}

Steps to Complete:

  1. Define the VersionManagerError enum in src/error.rs with appropriate variants for download, extraction, build, and installation failures.
  2. Refactor existing code that uses VersionManagerError(String) to use the new detailed variants, such as in the version manager implementation for Node.js and Python.
  3. Update error handling logic where relevant, to construct and return the new VersionManagerError types.
  4. Test the changes by simulating different failure scenarios to ensure the correct error type and message are produced.

Difficulty

Beginner-friendly, but requires understanding of Rust's error handling patterns and enums.

Files to Modify

This issue will improve error traceability and make debugging easier for users and developers.

ChrisX101010 commented 5 days ago

@harshdoesdev 👍