Commit f794d8a
authored
Don't panic in
## Objective
`AssetPath` deserialization panics if the path is malformed. This seems
a bit rude, and prevents the user from getting deserialization errors
that would help track down the problem.
## Solution
Instead of calling `AssetPath::parse`, call `AssetPath::try_parse` and
handle any errors.
Now, calling `ron::de::from_str` on `"a/b.test#"` returns a useful
error:
```rust
Err(SpannedError {
code: Message(
"Asset label must be at least one character. Either specify the label after the '#' or remove the '#'",
),
span: Span {
start: Position { line: 1, col: 2, },
end: Position { line: 1, col: 12 },
},
})
```
The PR also removes the `visit_string` method of the `AssetPath`
deserializer. `visit_string` is an optimization that avoids copies when
the deserializer can take ownership of the string (see [serde
docs](https://docs.rs/serde/latest/serde/de/trait.Visitor.html#method.visit_string)).
But `AssetPath` didn't take ownership of the string, so there's no
reason to implement it.
## Testing
```sh
cargo test -p bevy_asset
cargo run --example world_serialization
```AssetPath deserialization (#23935)1 parent 4dc8fb4 commit f794d8a
1 file changed
Lines changed: 10 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
680 | 680 | | |
681 | 681 | | |
682 | 682 | | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
691 | 687 | | |
692 | 688 | | |
693 | 689 | | |
| |||
772 | 768 | | |
773 | 769 | | |
774 | 770 | | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
775 | 777 | | |
776 | 778 | | |
777 | 779 | | |
| |||
0 commit comments