-
-
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
Better error reporting for embedded_path macro #11340
Better error reporting for embedded_path macro #11340
Conversation
A number of cases will panic, which is fine. The issue is there are two or three different errors that all report an unwrap on a None value, so they're hard to differentiate for the user.
This refactor does not change `embedded_path!`'s behavior. All cases that caused a panic before, will still cause a panic. But this change will provide the user diagnostic information that will hopefully help them right whatever issue is causing the panic. The original behavior was this: ``` #[test] #[should_panic(expected = "called `Option::unwrap()` on a `None` value")] fn test_embedded_path_original_behavior() { embedded_path!("NOT-IN-PATH", "b"), } ``` The changed behavior is this: ``` #[test] #[should_panic( expected = "Expected source path `NOT-IN-PATH` in file path `crates/bevy_asset/src/io/embedded/mod.rs`" )] fn test_embedded_path_original_behavior() { embedded_path!("NOT-IN-PATH", "b") } ```
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
As I was fixing the tests to work on Windows, I noticed the "/src/" hardcoding for embedded paths isn't going to work as is. That appears to be fixed by #10383, so perhaps this PR shouldn't be considered until that PR is closed. |
let crate_name = module_path!() | ||
.split(':') | ||
.next() | ||
.expect("Could not find crate name"); |
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.
Can we report the original string here for better diagnosability?
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.
Certainly. Is this the kind of error message you're looking for?
panic!("Could not find crate name. Expected ':' in module path `{}`", module_path!());
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.
Looks good: always nice to improve error messages like this.
In reviewing #10383, I'd suggest closing this PR and going with that one. It does what I wanted to do here and more. |
Objective
Better error reporting for embedded_path macro.
A number of cases will cause a panic, which is fine. The issue is there are two or three different possible panics that all report an unwrap on a None value, so they're hard to differentiate for the user, and they were difficult for me to diagnose as a user.
Solution
This refactor does not change
embedded_path!
's functional behavior. All cases that caused a panic before, will still cause a panic. However, this change will provide the user diagnostic information that will hopefully help them right whatever issue is causing the panic.The original behavior that caught me up was this:
The changed behavior is this:
Changelog