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:
Mike 2023-03-20 12:29:54 -07:00 committed by GitHub
parent e27f38a3e6
commit d58ed67fa4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(())
})