-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Change usage of anyhow to more specific error enums #10160
Comments
Personally I don't really know what your goal here is but you've come to a pretty large Rust project and by saying:
You've basically said "please redo your entire error handling strategy". That's a very large change to a project like Cargo and naturally isn't really one we'd just sort of off-hand agree with and start accepting PRs for. Cargo's error handling was designed long ago and hasn't really changed since. That's not to say that it's perfect but I don't think it's necessarily the most productive route to not ask for or try to understand historical context and simply propose complete 180 turnaround changes from Cargo's error handling strategy today. Cargo's error-handling strategy is designed to not be a maintenance burden on us while also enabling more sophisticated handling of errors where necessary. It's not really clear to me why Cargo's error handling today cannot be used to solve the issues you've mentioned here. I think it would be much better to reuse what Cargo does today instead of trying to design something new out-of-the-blue and completely change Cargo's internal idioms because of a few issues. |
Thanks for the response! It may sound like an ask for a rewrite, but I don't think it is that major. It's more of an ask for permission change a few places where an unnecessary layer of abstraction gets in the way of better error handling. I hope you agree that in the wider Rust ecosystem there's now an established pattern to use Cargo is big indeed, so it plays both roles at once, different in different parts of the codebase. In the library-like parts of Cargo, While downcasting technically works, it's not great:
|
Sorry for the delayed response, but there's a lot of changes and PRs in flight in Cargo which are all quite large and at least my own personal time for Cargo is quite limited. I basically don't have time to discuss the nuances of error handling in Cargo. I'm only one member of the Cargo team though and others might be interested in talking about this. |
Just had a talk with @Muscraft. This is mostly my idea but it would be great if we have this kind of error overhaul. It will help things like JSON format message (#8283) or developing Cargo's own lint rules with |
Triage: This is not extremely hard from the angle of technical aspect, though they are tremendously large amount of code need to touch. Hence @rustbot label +E-hard |
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 anyhowError
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:
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 #10159cargo 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
The text was updated successfully, but these errors were encountered: