-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Replace unwraps with expects in bevy_asset #3892
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
Conversation
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.
Not informed enough to comment on a lot of these. But it seems like in many cases there's some type of Error
being ignored that likely contains some useful information about what went wrong.
@@ -358,7 +362,7 @@ impl AssetServer { | |||
self.server | |||
.asset_io | |||
.watch_path_for_changes(asset_path.path()) | |||
.unwrap(); | |||
.expect("Could not watch path for changes."); |
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.
Seems like this one could be .watch_path_for_changes(asset_path.path())?;
@@ -399,7 +403,9 @@ impl AssetServer { | |||
let path = path.as_ref(); | |||
if !self.server.asset_io.is_directory(path) { | |||
return Err(AssetServerError::AssetFolderNotADirectory( | |||
path.to_str().unwrap().to_string(), | |||
path.to_str() | |||
.expect("Could not convert path to string.") |
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.
Seems like this should only fail if the path has invalid utf8, so the message could be made more specific.
Yep; that's my next pass for this PR. |
Co-authored-by: Charles <[email protected]>
Sorry, my mistake, the method is unwrap_or_else() not expect_or_else. My local setup is giving me some issues and I didn't notice the mistake. |
Co-authored-by: Charles <[email protected]>
Closing per discussion in #3899. |
# Objective - Manually running systems is a somewhat obscure process: systems must be initialized before they are run - The unwrap is rather hard to debug. ## Solution - Replace unwraps in `FunctionSystem` methods with expects (progress towards #3892). - Briefly document this requirement.
…ine#3947) # Objective - Manually running systems is a somewhat obscure process: systems must be initialized before they are run - The unwrap is rather hard to debug. ## Solution - Replace unwraps in `FunctionSystem` methods with expects (progress towards bevyengine#3892). - Briefly document this requirement.
…ine#3947) # Objective - Manually running systems is a somewhat obscure process: systems must be initialized before they are run - The unwrap is rather hard to debug. ## Solution - Replace unwraps in `FunctionSystem` methods with expects (progress towards bevyengine#3892). - Briefly document this requirement.
Objective
Solution
Meta
This is a very basic, mechanical pass to improve error handling.
I don't currently have a deep understanding of the internals (and they're likely to change), so the error messages provided are very localized. It would be nice to capture more information about the state in these expect messages as well before merging.
There are a few wasm-specific unwraps left in
wasm_asset_io.rs
that I didn't feel comfortable tackling. There are also some expects in test code left, which I felt were fine to keep.Like always, improvements are very welcome.