Skip to content

Refine error handling #20

@codcod

Description

@codcod

Problem: Some functions return Result<()> and print errors to the console directly. This makes it hard for calling functions to handle different error types or change the logging behavior.

Suggestion: Propagate errors using Result<()> and handle them at a higher level (e.g., in the execute method of a command). This makes the lower-level functions more reusable and testable.

Minimal change example (conceptual):

// In a function within src/github/api.rs
pub async fn some_api_call() -> Result<()> {
    let result = // ... api call
    if result.is_err() {
        println!("API call failed: {}", result.err().unwrap());
        return Ok(()); // Error is swallowed
    }
    // ...
    Ok(())
}

Instead of this pattern in a low-level function:

// In a function within src/github/api.rs
pub async fn some_api_call() -> Result<ApiResponse> {
    let response = // ... api call
    response.error_for_status().map_err(anyhow::Error::from)
    // ... return Ok(response)
}

The calling function in pr.rs would then handle the Result. This is a slightly larger change but significantly improves maintainability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorA code change (src or test) that neither fixes a bug nor adds a feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions