Skip to content

Change usage of anyhow to more specific error enums #10160

Open
@kornelski

Description

@kornelski

Problem

Most of Cargo's internal helper functions return anyhow::Error. This makes it difficult for callers of such functions to implement custom, specific error handling other than by downcasting. Fallible downcasting of anyhow Error to specific error types seems fragile: the error types are not checked at compile time, so if a helper method changes its implementation, error handling in callers can break at runtime.

Places where a specific error type could be useful:

Proposed Solution

I suggest gradually moving away from use of anyhow::Error (edit: for the internal helper functions and library interfaces, not all of Cargo), and use concrete error types (function or module-specific structs or enums). For a start this could be limited to private APIs.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cargo-apiArea: cargo-the-library API and internal code issuesA-diagnosticsArea: Error and warning messages generated by Cargo itself.C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`E-hardExperience: HardS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions