mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
add position to scene errors (#8065)
# Objective
- Fixes https://github.com/bevyengine/bevy/issues/6760
- adds line and position on line info to scene errors
```text
Before:
2023-03-12T22:38:59.103220Z WARN bevy_asset::asset_server: encountered an error while loading an asset: Expected closing `)`
After:
2023-03-12T22:38:59.103220Z WARN bevy_asset::asset_server: encountered an error while loading an asset: Expected closing `)` at scenes/test/scene.scn.ron:10:4
```
## Solution
- use span_error to get position info. This is what the ron crate does
internally to get the position info.
562963f887/src/options.rs (L158)
## Changelog
- added line numbers to scene errors
---------
Co-authored-by: Paul Hansen <mail@paul.rs>
This commit is contained in:
parent
e27f38a3e6
commit
d58ed67fa4
1 changed files with 12 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::serde::SceneDeserializer;
|
||||
use anyhow::Result;
|
||||
use anyhow::{anyhow, Result};
|
||||
use bevy_app::AppTypeRegistry;
|
||||
use bevy_asset::{AssetLoader, LoadContext, LoadedAsset};
|
||||
use bevy_ecs::world::{FromWorld, World};
|
||||
|
@ -35,7 +35,17 @@ impl AssetLoader for SceneLoader {
|
|||
let scene_deserializer = SceneDeserializer {
|
||||
type_registry: &self.type_registry.read(),
|
||||
};
|
||||
let scene = scene_deserializer.deserialize(&mut deserializer)?;
|
||||
let scene = scene_deserializer
|
||||
.deserialize(&mut deserializer)
|
||||
.map_err(|e| {
|
||||
let span_error = deserializer.span_error(e);
|
||||
anyhow!(
|
||||
"{} at {}:{}",
|
||||
span_error.code,
|
||||
load_context.path().to_string_lossy(),
|
||||
span_error.position,
|
||||
)
|
||||
})?;
|
||||
load_context.set_default_asset(LoadedAsset::new(scene));
|
||||
Ok(())
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue