-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Derive Error for more error types #10240
Conversation
This covers all types found by |
15ebdc4
to
544a6c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds thiserror as a dependency to bevy_transform, which might increase compilation time -- but I don't know of any situation where you might only use that but not any other crate that pulls in bevy_utils.
I think it already is a transitive dependency via bevy_ecs, so this might not be a significant change.
The contributors example has a LoadContributorsError type, but as it's an example I have not updated it. Doing that would mean either having a use bevy_internal::utils::thiserror::Error; in an example file, or adding thiserror as a dev-dependency to the main bevy crate.
Note that the bevy_utils crate should still be accessible via bevy::utils
, so bevy::utils::thiserror
I don't think updating the example blocks this PR.
Are we committed enough to this dependency to promote it in our examples? But also with error[E0433]: failed to resolve: use of undeclared crate or module `thiserror`
--> examples/games/contributors.rs:315:17
|
315 | #[derive(Debug, Error)]
| ^^^^^ use of undeclared crate or module `thiserror`
|
= note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) However (and unintuitively), this works: use bevy::utils::thiserror;
#[derive(Debug, thiserror::Error)]
enum LoadContributorsError {
#[error("An IO error occurred while reading the git log.")]
Io(#[from] io::Error),
#[error("The CARGO_MANIFEST_DIR environment variable was not set.")]
Var(#[from] VarError),
#[error("The git process did not return a stdout handle.")]
Stdout,
} If you think this is a good example, I can push a commit with this change. |
IMO yes: it's an ecosystem standard and really helpful to teach Rust newcomers (even if it's not particularly Bevy-related). |
Alright! Updated the example, too. |
This adds thiserror as a dependency to this crate. This might mean it pulls in syn now.
Note that thiserror was already a dependency, so this is just cleaning up the code and making it more concise.
This uses the reexport from `bevy::utils::thiserror`. Please note that the module has to be imported, not just the `Error` type, as macro relies on `thiserror` to be in scope.
5388246
to
3700a86
Compare
# Objective Align all error-like types to implement `Error`. Fixes bevyengine#10176 ## Solution - Derive `Error` on more types - Refactor instances of manual implementations that could be derived This adds thiserror as a dependency to bevy_transform, which might increase compilation time -- but I don't know of any situation where you might only use that but not any other crate that pulls in bevy_utils. The `contributors` example has a `LoadContributorsError` type, but as it's an example I have not updated it. Doing that would mean either having a `use bevy_internal::utils::thiserror::Error;` in an example file, or adding `thiserror` as a dev-dependency to the main `bevy` crate. --- ## Changelog - All `…Error` types now implement the `Error` trait
# Objective Align all error-like types to implement `Error`. Fixes bevyengine#10176 ## Solution - Derive `Error` on more types - Refactor instances of manual implementations that could be derived This adds thiserror as a dependency to bevy_transform, which might increase compilation time -- but I don't know of any situation where you might only use that but not any other crate that pulls in bevy_utils. The `contributors` example has a `LoadContributorsError` type, but as it's an example I have not updated it. Doing that would mean either having a `use bevy_internal::utils::thiserror::Error;` in an example file, or adding `thiserror` as a dev-dependency to the main `bevy` crate. --- ## Changelog - All `…Error` types now implement the `Error` trait
Objective
Align all error-like types to implement
Error
.Fixes #10176
Solution
Error
on more typesThis adds thiserror as a dependency to bevy_transform, which might increase compilation time -- but I don't know of any situation where you might only use that but not any other crate that pulls in bevy_utils.
The
contributors
example has aLoadContributorsError
type, but as it's an example I have not updated it. Doing that would mean either having ause bevy_internal::utils::thiserror::Error;
in an example file, or addingthiserror
as a dev-dependency to the mainbevy
crate.Changelog
…Error
types now implement theError
trait