Open
Description
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:
- handling of SSH auth failures. Customized error message exists, but it depends on a downcast.
- more readable and tailored output of build script error. Currently
ProcessError
is used for multiple purposes, and its generic verbose output has a high noise to signal ratio for build script failures. Presentation of build script errors is noisy, difficult to understand #10159 - better handling of
cargo new
in workspaces Feature Request: cargo new --in-workspace [directory] [name] #6378 (comment)
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
Labels
Area: cargo-the-library API and internal code issuesArea: Error and warning messages generated by Cargo itself.Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Experience: HardStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.